-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
NewFastHTTPHandler does not set response status code #1754
Comments
The handler sets the status code which is captured by Can you show an example of something going wrong? |
netHTTPResponseWriter is missing the initialization of statusCode, so when it propagates it propagates a nil value. |
But that's no problem, cause in fasthttp/fasthttpadaptor/adaptor.go Lines 98 to 100 in d3aa5a1
Or do you mean that you are setting a status code before you call the handler returned by Like I said, show me an example of this going wrong. |
Yes I mean to set the status code before calling the HTTPHandler. It needs to be set on line 59.
|
Interesting use case. But in that case can't you just turn it around and do this? if isBadRequest {
Render(c, dialog.BadRequest())
c.Status(http.StatusBadRequest)
} |
You might not know where the Status was set, if the HTTPHandler will reset it you need to get a copy beforehand to set it again afterwards. I found this issue while debugging Templ code using go.fiber, I don't control the adaptor, I just use it on my project. I think it should just respect the Status, the code above I just wrote it as an example. |
I don't think it happens very often that someone using a http handler will still also want to run fasthttp code. That's why you're the first one to have this issue. I'm afraid I don't have time to fix this now, but a pull request is always welcome. |
I recreated the issue because the reopen button is not on the original issue.
The NewFastHTTPHandler() handler does not set the Status code for the response:
https://github.com/valyala/fasthttp/blob/master/fasthttpadaptor/adaptor.go#L59
I have pointed the line of code that needs to be updated to set the status from the ctx response.
The code in line 65
fasthttp/fasthttpadaptor/adaptor.go
Line 65 in d3a9c74
Returns a nil value that eventually is changed to 200.
The fix needed is on line 59, the response
needs to changed to:
Line 65 needs to be removed since code is set by the caller, ctx already should contain the nil value or a status set by the caller.
The text was updated successfully, but these errors were encountered: