Skip to content

Response.WriteHeader treats 1xx informational status codes as the final status #3241

Open

Description

@vishr

Problem

echo.Response.WriteHeader handles every status code as final: it runs Before hooks, stores Status, and sets Committed = true. A handler that sends 103 Early Hints (supported by net/http since Go 1.19) therefore can't send its real status afterwards:

e.GET("/", func(c *echo.Context) error {
	c.Response().Header().Set("Link", "</style.css>; rel=preload; as=style")
	c.Response().WriteHeader(http.StatusEarlyHints)
	return c.String(http.StatusCreated, "ok")
})

The 201 is dropped with echo: response already written to client, net/http sends an implicit 200, and Response.Status and the request logger report 103.

Expected

Informational codes (100–199, except 101 Switching Protocols, which is final) should go straight to the underlying writer. They shouldn't run Before hooks or change Status or Committed, so the handler can still send the final status.

Found while reviewing #3239.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions