Skip to content
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

Merged
merged 2 commits into from
Sep 12, 2018
Merged

fetch: Send headers to JS #727

merged 2 commits into from
Sep 12, 2018

Conversation

qti3e
Copy link
Contributor

@qti3e qti3e commented Sep 10, 2018

This is a step toward #522,

(Personal note: 7caab7b)

js/fetch.ts Outdated
break;
}
}
for (; end > 0; --end) {
Copy link
Contributor Author

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/

Copy link
Member

@ry ry left a 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;
}
Copy link
Member

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.

src/handlers.rs Show resolved Hide resolved
src/handlers.rs Show resolved Hide resolved
@qti3e qti3e changed the title [WIP] Implement fetch headers fetch: Send headers to JS Sep 12, 2018
Copy link
Member

@ry ry left a 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 Show resolved Hide resolved
js/fetch.ts Outdated Show resolved Hide resolved
js/fetch.ts Outdated
const header = init[i];
if (header.length !== 2) {
throw new TypeError();
}
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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;

Copy link
Member

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");
});
Copy link
Member

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");

src/handlers.rs Show resolved Hide resolved
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks Parsa : )

@ry ry merged commit 41c70b1 into denoland:master Sep 12, 2018
@qti3e qti3e deleted the q/headers branch September 12, 2018 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants