Skip to content

Commit

Permalink
Merge pull request #11437 from wojtekmaj/create-headers
Browse files Browse the repository at this point in the history
Extract & use createHeaders helper
  • Loading branch information
timvandermeij authored Dec 23, 2019
2 parents 32c3434 + d40d336 commit bcf8ae3
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/display/fetch_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ function createFetchOptions(headers, withCredentials, abortController) {
};
}

function createHeaders(httpHeaders) {
const headers = new Headers();
for (const property in httpHeaders) {
const value = httpHeaders[property];
if (typeof value === 'undefined') {
continue;
}
headers.append(property, value);
}
return headers;
}

/** @implements {IPDFStream} */
class PDFFetchStream {
constructor(source) {
Expand Down Expand Up @@ -97,14 +109,7 @@ class PDFFetchStreamReader {
this._isStreamingSupported = !source.disableStream;
this._isRangeSupported = !source.disableRange;

this._headers = new Headers();
for (const property in this._stream.httpHeaders) {
const value = this._stream.httpHeaders[property];
if (typeof value === 'undefined') {
continue;
}
this._headers.append(property, value);
}
this._headers = createHeaders(this._stream.httpHeaders);

const url = source.url;
fetch(url, createFetchOptions(this._headers, this._withCredentials,
Expand Down Expand Up @@ -204,14 +209,7 @@ class PDFFetchStreamRangeReader {
this._abortController = new AbortController();
}

this._headers = new Headers();
for (const property in this._stream.httpHeaders) {
const value = this._stream.httpHeaders[property];
if (typeof value === 'undefined') {
continue;
}
this._headers.append(property, value);
}
this._headers = createHeaders(this._stream.httpHeaders);
this._headers.append('Range', `bytes=${begin}-${end - 1}`);

const url = source.url;
Expand Down

0 comments on commit bcf8ae3

Please sign in to comment.