Content disposition filename

File name is extracted from headers.
This commit is contained in:
Juan Salvador Perez Garcia 2018-01-13 09:01:50 +01:00 committed by Jonas Jenwald
parent 96c573ad38
commit eb1f6f4c24
8 changed files with 139 additions and 21 deletions

View file

@ -22,7 +22,9 @@ let url = __non_webpack_require__('url');
import {
AbortException, assert, createPromiseCapability
} from '../shared/util';
import { validateRangeRequestCapabilities } from './network_utils';
import {
extractFilenameFromHeader, validateRangeRequestCapabilities
} from './network_utils';
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
@ -74,6 +76,7 @@ class BaseFullReader {
this._done = false;
this._errored = false;
this._reason = null;
this._fileName = null;
this.onProgress = null;
let source = stream.source;
this._contentLength = source.length; // optional
@ -109,6 +112,10 @@ class BaseFullReader {
return this._isStreamingSupported;
}
get fileName() {
return this._fileName;
}
read() {
return this._readCapability.promise.then(() => {
if (this._done) {
@ -284,13 +291,15 @@ class PDFNodeStreamFullReader extends BaseFullReader {
this._headersCapability.resolve();
this._setReadableStream(response);
const getResponseHeader = (name) => {
// Make sure that headers name are in lower case, as mentioned
// here: https://nodejs.org/api/http.html#http_message_headers.
return this._readableStream.headers[name.toLowerCase()];
};
let { allowRangeRequests, suggestedLength, } =
validateRangeRequestCapabilities({
getResponseHeader: (name) => {
// Make sure that headers name are in lower case, as mentioned
// here: https://nodejs.org/api/http.html#http_message_headers.
return this._readableStream.headers[name.toLowerCase()];
},
getResponseHeader,
isHttp: stream.isHttp,
rangeChunkSize: this._rangeChunkSize,
disableRange: this._disableRange,
@ -301,6 +310,9 @@ class PDFNodeStreamFullReader extends BaseFullReader {
}
// Setting right content length.
this._contentLength = suggestedLength;
// Setting the file name from the response header
this._fileName = extractFilenameFromHeader(getResponseHeader);
};
this._request = null;