You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both of my notFoundHandler and methodNotAllowedHandler middlewares send a valid JSON response with:
bunrouter.JSON(w, err)
Where err is a custom HTTPError type with json marshaling tags.
The JSON marshaling does work and the response received on the client is something like:
{"code":"not_found","message":"no route found for /"}
But the Content-Type header received is text/plain; charset=utf-8.
🚀 The expected result
bunrouter.JSON should always set application/json as the Content-Type, even when used in special middlewares.
The text was updated successfully, but these errors were encountered:
aharbis
changed the title
Content-Type returned by JSON is application/text when used in special middlewares
Content-Type returned by JSON is not application/json when used in special middlewares
Aug 19, 2022
Actually, this may not be scoped to just those middlewares. I am also seeing similar behavior for other routes, where neither of the NotFound nor MethodNotFound handlers were involved.
// Changing the header map after a call to WriteHeader (or// Write) has no effect unless the HTTP status code was of the// 1xx class or the modified headers are trailers.
💡 The feature or bug you are proposing
Using
bunrouter.JSON
in handlers passed to eitherWithNotFoundHandler
orWithMethodNotAllowedHandler
results inapplication/text
Content-Type header.📄 The description of the bug or the logic behind your proposal
Constructing my router like this:
Both of my
notFoundHandler
andmethodNotAllowedHandler
middlewares send a valid JSON response with:Where
err
is a customHTTPError
type withjson
marshaling tags.The JSON marshaling does work and the response received on the client is something like:
But the Content-Type header received is
text/plain; charset=utf-8
.🚀 The expected result
bunrouter.JSON
should always setapplication/json
as the Content-Type, even when used in special middlewares.The text was updated successfully, but these errors were encountered: