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

fix(types)!: expose httpServer with Http2SecureServer union #14834

Merged
merged 3 commits into from
Nov 2, 2023

Conversation

lzt1008
Copy link
Contributor

@lzt1008 lzt1008 commented Oct 31, 2023

Description

The http.Server and Http2SecureServer types were previously asserted to HttpServer directly. This meant that some properties were potentially unusable:

return createSecureServer(
{
// Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM
// errors on large numbers of requests
maxSessionMemory: 1000,
...httpsOptions,
allowHTTP1: true,
},
// @ts-expect-error TODO: is this correct?
app,
) as unknown as HttpServer

This PR explicitly declare a HttpServer type as the union of the two server types. These two types share a large common property - only a small subset of properties are unavailable when using the union HttpServer type.

export type HttpServer = http.Server | Http2SecureServer

This makes property usage more strict and avoids impossible states when using the two server types interchangeably.

Additional context

Some properties are now inaccessible when using HttpServer:

http.Server only:

  • maxHeadersCount
  • maxRequestsPerSocket
  • timeout
  • headersTimeout
  • keepAliveTimeout
  • requestTimeout
  • closeAllConnections
  • closeIdleConnections

Http2SecureServer only:

  • addContext
  • getTicketKeys
  • setSecureContext
  • setTicketKeys
  • updateSettings

However, none of these properties were used in the current code. So the behavior impact of this type change is theoretically none.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Copy link

stackblitz bot commented Oct 31, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member

bluwy commented Nov 1, 2023

This will affect downstream plugins and projects that access the httpServer property so it will break their types. I'll run ecosystem-ci to check this if it's largely safe, but we're close to Vite 5 stable release now.

@bluwy
Copy link
Member

bluwy commented Nov 1, 2023

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 8477e1a: Open

suite result latest scheduled
analogjs success success
astro failure failure
histoire success success
ladle success success
laravel failure failure
marko failure failure
nuxt failure failure
nx failure failure
previewjs failure failure
qwik failure failure
rakkas success success
sveltekit failure failure
unocss success success
vike success success
vite-plugin-pwa success success
vite-plugin-react success success
vite-plugin-react-pages failure success
vite-plugin-react-swc failure failure
vite-plugin-svelte success success
vite-plugin-vue success success
vite-setup-catalogue success success
vitepress success success
vitest failure failure

bluwy
bluwy previously approved these changes Nov 2, 2023
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

I think we can give this a try. It also looks like we attempted this in the past (#10196) but reverted as it's breaking downstream. Now in the Vite 5 beta would be a good time to go with this.

EDIT: oh it looks like there's merge conflicts

@bluwy bluwy changed the title chore(types): use unified HttpServer type to avoid type assertion fix(types)!: expose httpServer with Http2SecureServer union Nov 2, 2023
@bluwy bluwy added p2-nice-to-have Not breaking anything but nice to have (priority) breaking change labels Nov 2, 2023
@lzt1008
Copy link
Contributor Author

lzt1008 commented Nov 2, 2023

I think we can give this a try. It also looks like we attempted this in the past (#10196) but reverted as it's breaking downstream. Now in the Vite 5 beta would be a good time to go with this.

EDIT: oh it looks like there's merge conflicts

Looks like new added AsyncDisposable conflicts with this, I've resolved this conflict.

@patak-dev patak-dev merged commit ab5bb40 into vitejs:main Nov 2, 2023
10 checks passed
sapphi-red added a commit to sapphi-red/vite that referenced this pull request Nov 6, 2023
patak-dev pushed a commit that referenced this pull request Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants