15
15
16
16
import { AbortException , assert , warn } from "../shared/util.js" ;
17
17
import {
18
+ createHeaders ,
18
19
createResponseStatusError ,
19
20
extractFilenameFromHeader ,
20
21
validateRangeRequestCapabilities ,
@@ -38,18 +39,6 @@ function createFetchOptions(headers, withCredentials, abortController) {
38
39
} ;
39
40
}
40
41
41
- function createHeaders ( httpHeaders ) {
42
- const headers = new Headers ( ) ;
43
- for ( const property in httpHeaders ) {
44
- const value = httpHeaders [ property ] ;
45
- if ( value === undefined ) {
46
- continue ;
47
- }
48
- headers . append ( property , value ) ;
49
- }
50
- return headers ;
51
- }
52
-
53
42
function getArrayBuffer ( val ) {
54
43
if ( val instanceof Uint8Array ) {
55
44
return val . buffer ;
@@ -66,7 +55,7 @@ class PDFFetchStream {
66
55
constructor ( source ) {
67
56
this . source = source ;
68
57
this . isHttp = / ^ h t t p s ? : / i. test ( source . url ) ;
69
- this . httpHeaders = ( this . isHttp && source . httpHeaders ) || { } ;
58
+ this . headers = createHeaders ( this . isHttp , source . httpHeaders ) ;
70
59
71
60
this . _fullRequestReader = null ;
72
61
this . _rangeRequestReaders = [ ] ;
@@ -123,17 +112,13 @@ class PDFFetchStreamReader {
123
112
this . _abortController = new AbortController ( ) ;
124
113
this . _isStreamingSupported = ! source . disableStream ;
125
114
this . _isRangeSupported = ! source . disableRange ;
126
-
127
- this . _headers = createHeaders ( this . _stream . httpHeaders ) ;
115
+ // Always create a copy of the headers.
116
+ const headers = new Headers ( stream . headers ) ;
128
117
129
118
const url = source . url ;
130
119
fetch (
131
120
url ,
132
- createFetchOptions (
133
- this . _headers ,
134
- this . _withCredentials ,
135
- this . _abortController
136
- )
121
+ createFetchOptions ( headers , this . _withCredentials , this . _abortController )
137
122
)
138
123
. then ( response => {
139
124
if ( ! validateResponseStatus ( response . status ) ) {
@@ -147,7 +132,7 @@ class PDFFetchStreamReader {
147
132
const { allowRangeRequests, suggestedLength } =
148
133
validateRangeRequestCapabilities ( {
149
134
getResponseHeader,
150
- isHttp : this . _stream . isHttp ,
135
+ isHttp : stream . isHttp ,
151
136
rangeChunkSize : this . _rangeChunkSize ,
152
137
disableRange : this . _disableRange ,
153
138
} ) ;
@@ -222,17 +207,14 @@ class PDFFetchStreamRangeReader {
222
207
this . _isStreamingSupported = ! source . disableStream ;
223
208
224
209
this . _abortController = new AbortController ( ) ;
225
- this . _headers = createHeaders ( this . _stream . httpHeaders ) ;
226
- this . _headers . append ( "Range" , `bytes=${ begin } -${ end - 1 } ` ) ;
210
+ // Always create a copy of the headers.
211
+ const headers = new Headers ( stream . headers ) ;
212
+ headers . append ( "Range" , `bytes=${ begin } -${ end - 1 } ` ) ;
227
213
228
214
const url = source . url ;
229
215
fetch (
230
216
url ,
231
- createFetchOptions (
232
- this . _headers ,
233
- this . _withCredentials ,
234
- this . _abortController
235
- )
217
+ createFetchOptions ( headers , this . _withCredentials , this . _abortController )
236
218
)
237
219
. then ( response => {
238
220
if ( ! validateResponseStatus ( response . status ) ) {
0 commit comments