Responding 204 leads to panic
- Dominant language
- Go
- Stars
- 86
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
Using HTTP status code 204 "No Content" to indicate that a request was successfully processed but no data is being returned leads to a panic.
```panic: respond: http: request method or response status code does not allow body
-> gopkg.in/matryer/respond%2ev1.with
-> /home/david/go/pkg/mod/gopkg.in/matryer/respond.v1@v1.0.1/respond.go:33
gopkg.in/matryer/respond%2ev1.WithStatus
/home/david/go/pkg/mod/gopkg.in/matryer/respond.v1@v1.0.1/respond.go:76
main.UserListOne
/home/david/dev/wfi_api/user.go:123
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5.(*Mux).routeHTTP
/home/david/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.Timeout.func1.1
/home/david/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/timeout.go:45
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.Recoverer.func1
/home/david/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/recoverer.go:38
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.RequestID.func1
/home/david/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/request_id.go:76
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.RealIP.func1
/home/david/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/realip.go:35
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5/middleware.RequestLogger.func1.1
/home/david/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/logger.go:57
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2047
github.com/go-chi/chi/v5.(*Mux).ServeHTTP
/home/david/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:88
net/http.serverHandler.ServeHTTP
/usr/local/go/src/net/http/server.go:2879
net/http.(*conn).serve
/usr/local/go/src/net/http/server.go:1930
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3034```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in respond.go at the WithStatus call shown in the panic trace, and reproduce the issue with an HTTP 204 response. Check the response behavior for status codes that do not allow a body; done means a 204 response completes without panicking and does not include a body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100