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

trailers/Deno.trailers support for Deno.serve and fetch #23632

Open
mmastrac opened this issue May 1, 2024 · 0 comments
Open

trailers/Deno.trailers support for Deno.serve and fetch #23632

mmastrac opened this issue May 1, 2024 · 0 comments
Labels
ext/fetch related to the ext/fetch ext/http related to ext/http web related to Web APIs

Comments

@mmastrac
Copy link
Contributor

mmastrac commented May 1, 2024

The WhatWG discussion on trailers in requests and responses is picking up a bit and it looks like CloudFlare is interested in implementing this as well.

We should implement trailers support for requests and responses behind a Deno-specific symbol that we can then swap out for the full API when standardized:

  • We add an --unstable only Deno.trailers unique symbol.
  • We add support for this symbol to Response, Request and the associated *Init objects. The field value would be Promise<Headers> or Promise<HeadersInit>, respectively
  • If we get support for this in the standard, Deno.trailers can be turned from a symbol into a string with the value trailers and marked as deprecated.
  • If a promise was provided in RequestInit for fetchor ResponseInit for Deno.serve, we'd await that promise before finalizing the associated HTTP transaction.

Initially this would only be supported for HTTP/2, however we could attempt to push support upstream to hyper for HTTP/1. I don't think that will be necessary, however.

This would allow for something like this to work:

Deno.serve(req => {
  const bodyHash = sha256(req.body);
  const hash = (await req[Deno.trailers])["SHA1-Of-Body"];
  validateBody(hash, bodyHash);
  const { stream, streamHash } = streamResponse(req.url);
  return new Response({ body: stream, [Deno.trailers]: (async () => ({ "SHA1-Of-Body": await streamHash }))() });
});
@mmastrac mmastrac added web related to Web APIs ext/fetch related to the ext/fetch ext/http related to ext/http labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext/fetch related to the ext/fetch ext/http related to ext/http web related to Web APIs
Projects
None yet
Development

No branches or pull requests

1 participant