SetContentType middleware breaks Content-Type detection for requests

Open
#3 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
api

Research direction

Start by locating SetContentType, GetRequestContentType, and DefaultDecoder, then trace how the shared context key is read for request Content-Type detection. Confirm the existing middleware and decoder behavior, identify a focused regression test location, and consider the issue's proposed separation of context state; done means response handling no longer interferes with request detection.

Written by the indexing model from the issue text.

Description

The documentation for SetContentType only mentions responses and says nothing of requests:

SetContentType is a middleware that forces response Content-Type.

However, this breaks Content-Type detection for requests in the DefaultDecoder because SetContentType and GetRequestContentType share the same context key.

It's not obvious to me why GetRequestContentType even looks at the context, as that seems to betray the function name. But if that behavior is going to stay, I suggest using a separate context key so that SetContentType does not interfere.

Dominant language
Go
Stars
341
Forks
68
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from go-chi/render

All issues in go-chi/render

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.