@@ -23,18 +23,18 @@ const kHeaders = Symbol('headers')
2323
2424class Response extends Body {
2525 constructor ( {
26- type = 'default' ,
26+ type,
2727 url,
2828 resume,
2929 abort,
30- statusCode = 0 ,
30+ statusCode,
3131 headers,
3232 context
3333 } ) {
3434 super ( resume , abort )
3535
36- this [ kType ] = type
37- this [ kStatus ] = statusCode
36+ this [ kType ] = type || 'default'
37+ this [ kStatus ] = statusCode || 0
3838 this [ kUrlList ] = [ url ]
3939 this [ kHeaders ] = headers
4040
@@ -160,15 +160,21 @@ class FetchHandler extends AsyncResource {
160160 type : 'opaqueredirect' ,
161161 url : this . url
162162 } )
163+ // TODO (fix): Should be "null" body.
164+ // TODO (fix): What to do with Readable?
165+ util . destroy ( body )
163166 } else {
164167 body = new Response ( {
165168 type : 'error' ,
166169 url : this . url
167170 } )
171+ // TODO (fix): Should be "null" body.
172+ // TODO (fix): What to do with Readable?
168173 util . destroy ( body , new Error ( 'redirect' ) )
169174 }
170175 } else {
171176 body = new Response ( {
177+ type : 'default' ,
172178 url : this . url ,
173179 resume,
174180 abort,
@@ -260,20 +266,21 @@ function fetch (opts, callback) {
260266 throw new NotSupportedError ( )
261267 }
262268
263- if (
264- opts . redirect !== undefined &&
265- opts . redirect !== 'follow' &&
266- opts . redirect !== 'error'
267- ) {
268- // TODO: Implement
269- throw new NotSupportedError ( )
269+ if ( opts . redirect != null ) {
270+ // TODO: Validate
271+ } else {
272+ opts . redirect = 'follow'
270273 }
271274
272275 if ( opts . integrity ) {
273276 // TODO: Implement
274277 throw new NotSupportedError ( )
275278 }
276279
280+ if ( opts . keepalive ) {
281+ // Ignore
282+ }
283+
277284 const headers = new Headers ( opts . headers )
278285
279286 if ( ! headers . has ( 'accept' ) ) {
@@ -297,7 +304,7 @@ function fetch (opts, callback) {
297304 method : normalizeAndValidateRequestMethod ( opts . method || 'GET' ) ,
298305 body,
299306 headers : headers ? ( headers [ kHeadersList ] || headers ) : null ,
300- maxRedirections : 20 // https://fetch.spec.whatwg.org/#concept-http-redirect-fetch
307+ maxRedirections : opts . redirect === 'follow' ? 20 : 0 // https://fetch.spec.whatwg.org/#concept-http-redirect-fetch
301308 } , new FetchHandler ( opts , callback ) )
302309 } catch ( err ) {
303310 if ( typeof callback !== 'function' ) {
0 commit comments