Skip to content

Commit

Permalink
fix: fetch redirect modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 3, 2021
1 parent da556ab commit 8731017
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ https://fetch.spec.whatwg.org/#request-class
* **mode** *not supported*
* **credentials** *not supported*
* **cache** *not supported*
* **redirect** `RequestRedirect` *only `"follow"` supported*
* **redirect** `RequestRedirect`
* **integrity** *not supported*
* **keepalive** *not supported*
* **signal** `AbortSignal?`
Expand Down
27 changes: 16 additions & 11 deletions lib/api/api-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ const kHeaders = Symbol('headers')

class Response extends Body {
constructor ({
type = 'default',
type,
url,
resume,
abort,
statusCode = 0,
statusCode,
headers,
context
}) {
super(resume, abort)

this[kType] = type
this[kStatus] = statusCode
this[kType] = type || 'default'
this[kStatus] = statusCode || 0
this[kUrlList] = [url]
this[kHeaders] = headers

Expand Down Expand Up @@ -160,15 +160,21 @@ class FetchHandler extends AsyncResource {
type: 'opaqueredirect',
url: this.url
})
// TODO (fix): Should be "null" body.
// TODO (fix): What to do with Readable?
util.destroy(body)
} else {
body = new Response({
type: 'error',
url: this.url
})
// TODO (fix): Should be "null" body.
// TODO (fix): What to do with Readable?
util.destroy(body, new Error('redirect'))
}
} else {
body = new Response({
type: 'default',
url: this.url,
resume,
abort,
Expand Down Expand Up @@ -260,20 +266,19 @@ function fetch (opts, callback) {
throw new NotSupportedError()
}

if (
opts.redirect !== undefined &&
opts.redirect !== 'follow' &&
opts.redirect !== 'error'
) {
// TODO: Implement
throw new NotSupportedError()
if (opts.redirect) {
// TODO: Validate
}

if (opts.integrity) {
// TODO: Implement
throw new NotSupportedError()
}

if (opts.keepalive) {
// Ignore
}

const headers = new Headers(opts.headers)

if (!headers.has('accept')) {
Expand Down

0 comments on commit 8731017

Please sign in to comment.