@@ -83,7 +83,6 @@ class RedirectHandler {
83
83
}
84
84
85
85
onRequestStart ( controller , context ) {
86
- this . location = null
87
86
this . handler . onRequestStart ?. ( controller , { ...context , history : this . history } )
88
87
}
89
88
@@ -136,9 +135,7 @@ class RedirectHandler {
136
135
// Remove headers referring to the original URL.
137
136
// By default it is Host only, unless it's a 303 (see below), which removes also all Content-* headers.
138
137
// https://tools.ietf.org/html/rfc7231#section-6.4
139
- this . opts . headers = this . opts . headers
140
- ? cleanRequestHeaders ( this . opts . headers , statusCode === 303 , this . opts . origin !== origin )
141
- : this . opts . headers
138
+ this . opts . headers = cleanRequestHeaders ( this . opts . headers , statusCode === 303 , this . opts . origin !== origin )
142
139
this . opts . path = path
143
140
this . opts . origin = origin
144
141
this . opts . maxRedirections = 0
@@ -191,26 +188,38 @@ class RedirectHandler {
191
188
}
192
189
193
190
// https://tools.ietf.org/html/rfc7231#section-6.4.4
194
- function shouldRemoveHeader ( name , removeContent , unknownOrigin ) {
195
- if ( name . length === 4 ) {
196
- return name === 'host'
191
+ function shouldRemoveHeader ( header , removeContent , unknownOrigin ) {
192
+ if ( header . length === 4 ) {
193
+ return util . headerNameToString ( header ) === 'host'
197
194
}
198
- if ( removeContent && name . startsWith ( 'content-' ) ) {
195
+ if ( removeContent && util . headerNameToString ( header ) . startsWith ( 'content-' ) ) {
199
196
return true
200
197
}
201
- if ( unknownOrigin && ( name . length === 13 || name . length === 6 || name . length === 19 ) ) {
198
+ if ( unknownOrigin && ( header . length === 13 || header . length === 6 || header . length === 19 ) ) {
199
+ const name = util . headerNameToString ( header )
202
200
return name === 'authorization' || name === 'cookie' || name === 'proxy-authorization'
203
201
}
204
202
return false
205
203
}
206
204
207
205
// https://tools.ietf.org/html/rfc7231#section-6.4
208
206
function cleanRequestHeaders ( headers , removeContent , unknownOrigin ) {
209
- const ret = util . normalizeHeaders ( headers )
210
- for ( const name of Object . keys ( ret ) ) {
211
- if ( shouldRemoveHeader ( name , removeContent , unknownOrigin ) ) {
212
- delete ret [ name ]
207
+ const ret = [ ]
208
+ if ( Array . isArray ( headers ) ) {
209
+ for ( let i = 0 ; i < headers . length ; i += 2 ) {
210
+ if ( ! shouldRemoveHeader ( headers [ i ] , removeContent , unknownOrigin ) ) {
211
+ ret . push ( headers [ i ] , headers [ i + 1 ] )
212
+ }
213
+ }
214
+ } else if ( headers && typeof headers === 'object' ) {
215
+ const entries = typeof headers [ Symbol . iterator ] === 'function' ? headers : Object . entries ( headers )
216
+ for ( const [ key , value ] of entries ) {
217
+ if ( ! shouldRemoveHeader ( key , removeContent , unknownOrigin ) ) {
218
+ ret . push ( key , value )
219
+ }
213
220
}
221
+ } else {
222
+ assert ( headers == null , 'headers must be an object or an array' )
214
223
}
215
224
return ret
216
225
}
0 commit comments