valyala/fasthttp

NewFastHTTPHandler does not set response status code

Open

#1.754 aberto em 9 de abr. de 2024

Ver no GitHub
 (7 comments) (0 reactions) (0 assignees)Go (1.755 forks)batch import
help wanted

Métricas do repositório

Stars
 (21.741 stars)
Métricas de merge de PR
 (Mesclagem média 1d 11h) (34 fundiu PRs em 30d)

Description

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 https://github.com/valyala/fasthttp/blob/d3a9c74c92588e83c465057c243e05b46d9118f7/fasthttpadaptor/adaptor.go#L65 Returns a nil value that eventually is changed to 200.

The fix needed is on line 59, the response

w := netHTTPResponseWriter{
	w:   ctx.Response.BodyWriter(),
	ctx: ctx,
}

needs to changed to:

w := netHTTPResponseWriter{
	w:   ctx.Response.BodyWriter(),
	statusCode: ctx.Response.StatusCode(), <---- this is needed
	ctx: ctx,
}

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.

Guia do colaborador