-
Notifications
You must be signed in to change notification settings - Fork 352
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 the dev server issue when proxy server returns 304 while redirect status is force set to 200 #865
Conversation
currently if we have a redirect rule in netlify.toml with force = true and status = 200 the response from proxy server will always be 200 this behavior is problematic when the proxy returns 304 with empty body the browser will always render a blank page the fix is to leave 3xx code back to the browser and never override
@@ -132,7 +132,12 @@ function initializeProxy(port, distDir, projectDir) { | |||
if (!isEmpty(pathHeaderRules)) { | |||
Object.entries(pathHeaderRules).forEach(([key, val]) => res.setHeader(key, val)) | |||
} | |||
res.writeHead(req.proxyOptions.status || proxyRes.statusCode, proxyRes.headers) | |||
// leave 3xx redirects handling to browser | |||
if (proxyRes.statusCode >= 300 && proxyRes.statusCode < 400) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I'm considering we probably should always return the proxyRes.statusCode, no matter it is 3xx or 4xx or 5xx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening this PR @bencao. The reason we have req.proxyOptions.status
is to force a certain status code, for example, 200!
or 404!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configuration like this is a bit vague, what if the api server returns http 500?
[[redirects]]
from = "/search"
to = "https://api.mysearch.com"
status = 200
force = true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a user, my actual intention is basically requesting a server side transparent proxy, not enforcing the status code to 200
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would still enforce 200
as status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.. do you have some ideas about how we can gracefully solve the above proxy server 304 resulted in blank page issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try out this branch #843 and see if that fixes the problem for you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the branch, it seems to be a bit too complicated to solve my very specific problem..
close and waiting for a better approach |
- Summary
currently if we have a redirect rule in netlify.toml with
force = true and status = 200
the response from proxy server will always be 200
this behavior is problematic when the proxy returns 304 with empty body
the browser will always render a blank page
the change proposed in this PR is to leave 3xx code back to the browser and never override
- Test plan
Before: Page Request return Status 200 with empty Body
After: Page Request return Status 304
- Description for the changelog
when proxy server returns status code between 300 and 399, the return status will honor proxy server status instead of using the one designated in redirection rule.