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

v2 migration #787

Open
pi0 opened this issue Jun 24, 2024 · 4 comments
Open

v2 migration #787

pi0 opened this issue Jun 24, 2024 · 4 comments

Comments

@pi0
Copy link
Member

pi0 commented Jun 24, 2024

Note

This is a tracker issue for H3 v2 release. You can try with h3-nightly@2x

Migration guide:

@pi0 pi0 added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2024
@pi0 pi0 changed the title v2 v2 Roadmap Jun 24, 2024
@pi0 pi0 pinned this issue Jun 24, 2024
@AaronDewes
Copy link

Why did you stop using destr? It's prevention of prototype pollution seemed quite useful.

@pi0
Copy link
Member Author

pi0 commented Jul 8, 2024

@AaronDewes mainly for bundle size. But i am up to add a replacement util for safe read (#819, feel free to make a PR for it!)

@pi0 pi0 changed the title v2 Roadmap v2 migration Jul 11, 2024
@magne4000
Copy link

magne4000 commented Jul 15, 2024

What would you think of the following approach to handle Response manipulation, now that standard web Response is the de-facto representation?

defineEventHandler({
  handler(...),
  // Here response type would always be Response
  onBeforeResponse(event, response: Response) {
    // We can then edit the response headers
	response.headers.set('X', 'Y');
    // Or even return a new one?
    return new Response(...);
  }
});

// Another approach: Update EventHandler definition so that we can return a Response Handler
defineEventHandler(event => {
  // return a Response handler
  return (response: Response) => {
    response.headers.set('X', 'Y');
    return response;
  }
});

The benefits I see are:

  • Make most of Response utils deprecated, streamlining even more the v2 approach.
  • Allow tool authors to declare their middleware once in a universal manner, and have h3 (or any other server) ingest it without overhead.

@pi0
Copy link
Member Author

pi0 commented Jul 17, 2024

@magne4000 With #829 h3 will be web-first with event.response.headers to allow modification of headers. Creating multiple Response objects for middleware might have performance overhead and h3 (v2) by design expects explicit return for body, other partials can be set via event.response and Web standard APIs. Once landed, would love to hear your feedback.

This was referenced Jul 18, 2024
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

No branches or pull requests

3 participants