-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetch: Send headers to JS #727
Conversation
js/fetch.ts
Outdated
break; | ||
} | ||
} | ||
for (; end > 0; --end) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/end > 0/end > start/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start! Thanks for doing this. I’d say leave out all the cors stuff in order to keep this patch small - it can be added later - I’m primarily interested in getting access to headers at all.
Needs tests.
js/fetch.ts
Outdated
return false; | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think it’s necessary at this stage to be fully compliant with web fetch - but I appreciate the effort. If we’re to land this code each of these functions should have unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few comments.
js/fetch.ts
Outdated
const header = init[i]; | ||
if (header.length !== 2) { | ||
throw new TypeError(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary? Multiple values with the same key are allowed in http headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ry This implementation already supports multiple values for the same key, header.length !== 2)
is based on this https://fetch.spec.whatwg.org/#concept-headers-fill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok - then can you add a test where it shows this throwing a TypeError?
js/fetch_test.ts
Outdated
testPerm({ net: true }, async function fetchHeaders() { | ||
const response = await fetch("http:https://localhost:4545/package.json"); | ||
const headers = response.headers; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove line break
js/fetch_test.ts
Outdated
const headers = response.headers; | ||
|
||
assertEqual(headers.get("Content-Type"), "application/json"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add one more for good measure
assert(headers.get("Server").startsWith("SimpleHTTP");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks Parsa : )
This is a step toward #522,
(Personal note: 7caab7b)