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

refactor: "Deno.serve()" API uses "Deno.serveHttp()" internally #18568

Merged
merged 22 commits into from
Apr 3, 2023

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Apr 2, 2023

This commit changes implementation of "Deno.serve()" API to use
"Deno.serveHttp()" under the hood. This change will allow us to
remove the "flash" server implementation, bringing stability to the
"Deno.serve()" API.

"cli/tests/unit/flash_test.ts" was renamed to "serve_test.ts".

Closes #15574
Closes #15504
Closes #15646
Closes #15909
Closes #15911
Closes #16828
Closes #18046
Closes #15869

@@ -301,51 +301,6 @@ Deno.test(
},
);

Deno.test(
{ permissions: { net: true } },
async function httpReadHeadersAfterClose() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is no longer necessary. Deno.serveHttp() returns properly formed response (ie. it doesn't do lazy loading of data), so headers are still available after the connection has been closed. This will allow us to remove some code in ext/fetch/23_request.js

// https://github.com/denoland/deno/issues/17291
Deno.test(
{ permissions: { net: true } },
{ permissions: { net: true }, ignore: true },
Copy link
Member Author

Choose a reason for hiding this comment

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

@littledivy please take a look

Copy link
Member Author

Choose a reason for hiding this comment

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

It appears this test was broken as well - there's no problem pushing strings to a ReadableStream, unless it has type: "bytes"

@@ -1122,68 +1079,6 @@ Deno.test(
},
);

Deno.test("upgradeHttpRaw tcp", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This unstable API will be removed along with flash implementation. Effectively there's no way to test it and the API will always throw.

Deno.test(
{ permissions: { net: true } },
{ permissions: { net: true }, ignore: true },
Copy link
Member Author

Choose a reason for hiding this comment

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

@littledivy please take a look

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand why this test requires Content-Length: 0 for the HEAD requests. It appears Hyper is not doing that and it's not mandatory to send this header. Can we remove this test case?

Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be any need for a zero Content-Length header, implicit or explicit. Does node have one? Even then, that's probably better to keep in the polyfill.

@bartlomieju bartlomieju marked this pull request as ready for review April 2, 2023 22:54
Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

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

LGTM! I think test changes are very reasonable.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

I still think the cookie coalescing behaviour is not correct. Using ; as a cookie separator is correct, but using it as a header separator is not correct. The header separator is always , . Multiple headers with the same name may be coalesced together using the , (except set-cookie, which is special cased). This behaviour must not be different for cookie headers.

It is possible that this is a bug in fetch. If it is, we can fix it in a different PR. We need to have a test that the wire representation of the below response is either cookie: foo=bar\r\ncookie: bar=foo\r\n or cookie: foo=bar, bar=foo\r\n, but not cookie: foo=bar; bar=foo\r\n.

const h = new Headers();
h.append("cookie", "foo=bar");
h.append("cookie", "bar=foo");
console.log(h.get("cookie")); // "foo=bar, bar=foo"

new Response("", { headers: h })

The fetch spec requires that Headers objects do not treat cookie specially, and it mandates that any coalescing of headers must use , .

@lucacasonato
Copy link
Member

Also we should have a test where we send the HTTP server a request using something other than fetch (ideally a hand-written H1 request), with definitely not coalesced cookie headers. The representation in req.headers should be , seperated, not ;. If it isn't there is an issue in hyper we'll have to look into.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

Retracting my request-changes, because this behaviour is already the case with serveHttp. See

deno/ext/http/lib.rs

Lines 555 to 560 in 6d68392

// We treat cookies specially, because we don't want them to get them
// mangled by the `Headers` object in JS. What we do is take all cookie
// headers and concat them into a single cookie header, separated by
// semicolons.
let cookie_sep = "; ".as_bytes();
let mut cookies = vec![];

@bartlomieju bartlomieju merged commit 2846bbe into denoland:main Apr 3, 2023
@bartlomieju bartlomieju deleted the deno_serve_serve_http branch April 3, 2023 15:44
bartlomieju added a commit that referenced this pull request Apr 3, 2023
With #18568 landed we no longer
need "ext/flash". 

This commit removes "deno_flash" extension completely.

This should have some impact on the binary and snapshot size.

Closes #17356
@sant123
Copy link

sant123 commented Apr 3, 2023

Does this solve #16267?

@bartlomieju
Copy link
Member Author

Does this solve #16267?

@sant123, yes it's now solved.

levex pushed a commit that referenced this pull request Apr 12, 2023
This commit changes implementation of "Deno.serve()" API to use
"Deno.serveHttp()" under the hood. This change will allow us to
remove the "flash" server implementation, bringing stability to the
"Deno.serve()" API.

"cli/tests/unit/flash_test.ts" was renamed to "serve_test.ts".

Closes #15574
Closes #15504
Closes #15646
Closes #15909
Closes #15911
Closes #16828
Closes #18046
Closes #15869
levex pushed a commit that referenced this pull request Apr 12, 2023
With #18568 landed we no longer
need "ext/flash". 

This commit removes "deno_flash" extension completely.

This should have some impact on the binary and snapshot size.

Closes #17356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants