-
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
fasthttp not writing headers on error #444
Comments
|
Well, after thorough debugging I am not exactly sure anymore if the issue is in func (r *Router) HandleRequest(ctx *fasthttp.RequestCtx) {
c := r.pool.Get().(*Context)
c.init(ctx)
c.handlers, c.pnames = r.find(string(ctx.Method()), string(ctx.Path()), c.pvalues)
if err := c.Next(); err != nil {
r.handleError(c, err)
}
r.pool.Put(c)
} All registered handlers for each path are evaluated in func (r *Router) handleError(c *Context, err error) {
if httpError, ok := err.(HTTPError); ok {
c.Error(httpError.Error(), httpError.StatusCode())
} else {
c.Error(err.Error(), http.StatusInternalServerError)
}
}
func (ctx *RequestCtx) Error(msg string, statusCode int) {
ctx.Response.Reset()
ctx.SetStatusCode(statusCode)
ctx.SetContentTypeBytes(defaultContentType)
ctx.SetBodyString(msg)
} Apparently, no custom headers are added to the response, only status code and content type. However, the question is if this is intentional or not. |
Judging by the code I guess it was intentional. It is possible that the user already set a header such as Now the question is why The fact remains that we can't change this behavior anymore now without breaking things for other users. |
I am using fasthttp-routing to make a server side application and I have just tried to add a header with allowed authentication when returning http error 401. However, I can't see the header in the response. After some investigation, I concluded that the problem is in this library in file
server.go
in functionwriteFastError
.Would it be possible for you to add some function to write all headers together with the message?
The text was updated successfully, but these errors were encountered: