You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ERR_HTTP_HEADERS_SENT with 5.3.0 / 5.3.1 and https-proxy-agent configured #17520
Run npm install
Replace https://example.org with an actual https proxy in vite.config.js (i don't know a public available one, sorry)
Run npm run dev
First click on the "Without proxy agent" button, you should see the expected result then.
Now click on the "With proxy agent" button, the ERR_HTTP_HEADERS_SENT should appear in the console.
System Info
Binaries:
Node: 18.15.0
npm: 9.5.0
Used Package Manager
npm
Logs
Click to expand!
node:_http_outgoing:663
throw new ERR_HTTP_HEADERS_SENT('set');
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:399:5)
at ClientRequest.setHeader (node:_http_outgoing:663:11)
at setOriginHeader (file:///-------/node_modules/vite/dist/node/chunks/dep-BcXSligG.js:61768:16)
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
The exception comes from a commit introduced in vite@5.3.0-beta.0 (7b0a65e).
This commit will modify the origin in the proxied request header by default, sometimes it will throw exception Cannot set headers after they are sent to the client.
In my case, I observed that the origin does not exist in the GET request header, and no exception is triggered. However, the origin exists in the POST request header, which triggers an exception. (why?)
Modify the origin in request headers is only necessary when the server-side explicitly checks for it. In most other scenarios, it is not required.
Three solutions:
Disable modify of origin by default
Check proxyReq.headersSent before modifying origin
Activity
bolt-new-by-stackblitz commentedon Jun 19, 2024
pfdgithub commentedon Jun 19, 2024
Encountered the same issue.
The exception comes from a commit introduced in
vite@5.3.0-beta.0(7b0a65e).This commit will modify the
originin the proxied request header by default, sometimes it will throw exceptionCannot set headers after they are sent to the client.In my case, I observed that the
origindoes not exist in the GET request header, and no exception is triggered. However, theoriginexists in the POST request header, which triggers an exception. (why?)Modify the origin in request headers is only necessary when the server-side explicitly checks for it. In most other scenarios, it is not required.
Three solutions:
originby defaultproxyReq.headersSentbefore modifyingoriginoriginbefore entering the vite proxybluwy commentedon Jun 24, 2024
This seems the be the best-fix for me, but I'm not too familiar with the original change.
@johnhunter @sapphi-red do you have thoughts on this?
johnhunter commentedon Jun 24, 2024
Option 2 sounds like a good solution. I'll have a proper look when I'm back at my desk.
johnhunter commentedon Jun 25, 2024
I'll address this along with #17562