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

@ -17,8 +17,8 @@ import {
AbortException, assert, createPromiseCapability
} from '../shared/util';
import {
createResponseStatusError, validateRangeRequestCapabilities,
validateResponseStatus
createResponseStatusError, extractFilenameFromHeader,
validateRangeRequestCapabilities, validateResponseStatus
} from './network_utils';
function createFetchOptions(headers, withCredentials) {
@ -67,6 +67,7 @@ class PDFFetchStream {
class PDFFetchStreamReader {
constructor(stream) {
this._stream = stream;
this._fileName = null;
this._reader = null;
this._loaded = 0;
let source = stream.source;
@ -100,11 +101,13 @@ class PDFFetchStreamReader {
this._reader = response.body.getReader();
this._headersCapability.resolve();
const getResponseHeader = (name) => {
return response.headers.get(name);
};
let { allowRangeRequests, suggestedLength, } =
validateRangeRequestCapabilities({
getResponseHeader: (name) => {
return response.headers.get(name);
},
getResponseHeader,
isHttp: this._stream.isHttp,
rangeChunkSize: this._rangeChunkSize,
disableRange: this._disableRange,
@ -112,6 +115,7 @@ class PDFFetchStreamReader {
this._contentLength = suggestedLength;
this._isRangeSupported = allowRangeRequests;
this._fileName = extractFilenameFromHeader(getResponseHeader);
// We need to stop reading when range is supported and streaming is
// disabled.
@ -131,6 +135,10 @@ class PDFFetchStreamReader {
return this._contentLength;
}
get fileName() {
return this._fileName;
}
get isRangeSupported() {
return this._isRangeSupported;
}