valyala/fasthttp

NewFastHTTPHandler does not set response status code

Open

#1754 aperta il 9 apr 2024

Vedi su GitHub
 (7 commenti) (0 reazioni) (0 assegnatari)Go (1755 fork)batch import
help wanted

Metriche repository

Star
 (21.741 star)
Metriche merge PR
 (Merge medio 3g) (44 PR mergiate in 30 g)

Descrizione

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.

Guida contributor