valyala/fasthttp

NewFastHTTPHandler does not set response status code

Open

#1 754 ouverte le 9 avr. 2024

Voir sur GitHub
 (7 commentaires) (0 réactions) (0 assignés)Go (1 755 forks)batch import
help wanted

Métriques du dépôt

Stars
 (21 741 stars)
Métriques de merge PR
 (Merge moyen 1j 11h) (34 PRs mergées en 30 j)

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.

Guide contributeur