Skip to content

middleware: GetHead advertises HEAD in the 405 Allow header#1095

Open
c-tonneslan wants to merge 1 commit into
go-chi:masterfrom
c-tonneslan:fix/gethead-allow-header
Open

middleware: GetHead advertises HEAD in the 405 Allow header#1095
c-tonneslan wants to merge 1 commit into
go-chi:masterfrom
c-tonneslan:fix/gethead-allow-header

Conversation

@c-tonneslan

Copy link
Copy Markdown

Closes #1030.

`GetHead` routes undefined HEAD requests through the matching GET handler, but the Allow header on a 405 response only came from the methods explicitly registered with the router. A GET-only route returned `Allow: GET` and never mentioned the implicit HEAD support, so clients thought HEAD wasn't allowed when in fact it was.

Wrap the response writer and add HEAD to the Allow header at `WriteHeader` time when the response is a 405 and Allow already lists GET. Responses without GET, and 405s where HEAD is already in Allow, are left alone.

Added `TestGetHead_AllowHeaderIncludesHead` covering the regression.

GetHead routes undefined HEAD requests through the matching GET
handler, but the Allow header on a 405 response only came from the
methods explicitly registered with the router. A GET-only route
returned `Allow: GET` and never mentioned the implicit HEAD support,
which left clients thinking HEAD wasn't allowed when in fact it was.

Wrap the response writer and add HEAD to the Allow header at
WriteHeader time when the response is a 405 and Allow already lists
GET. Existing responses without GET, and 405s where HEAD is already
present, are left alone.

Closes go-chi#1030.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

middleware.GetHead doesn't set Allow header

1 participant