-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
caddyhttp: Implement status_code handler #3313
caddyhttp: Implement status_code handler #3313
Conversation
22d6347
to
001765c
Compare
Isn't the functionality duplicate of
and the |
Yes that's true, but there's no way to specify an empty body via Caddyfile, and the syntax wouldn't allow for it either. |
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 this approach is not quite right. Instead we need a handler that wraps the ResponseWriter, and has its own WriteHeader method, so that when WriteHeader is called, the configured status code is written instead of the one passed in to WriteHeader.
This functionality might overlap with another pending feature request, I'll look into it more this week.
Yeah I see what you mean. I made this PR before actually trying it cause I was overconfident 😅 I needed to
|
001765c
to
1ab3e02
Compare
1ab3e02
to
21b58f0
Compare
Turns out It works now, I think this is what you were thinking of. That said, do you think it would make sense at all to change StaticResponse to wrap the response writer like this and chain if only the status is specified and no body? In other words, keep the response body the same, but just update the status code if that's the only parameter. Cause then we could do the same but with just the
|
I think the solution for this problem and #2920 are the same, and I wonder if the right place for it is actually in the existing The idea is that you capture the response, like you're doing, but then when WriteHeader is called, we invoke a subroute (handler chain) to be evaluated. In theory, this would allow the user to customize the status code that gets written, along with the headers and body if they want to, based on the response headers, which is something that can't currently be done. |
As noted in #3312 (comment), this isn't really the right approach. Closing. |
Closes #3312
Adds a simple
status_code
handler which simply modifies the HTTP status code of a response.JSON:
Caddyfile:
Example usecase:
Caddyfile:
Request: