Skip to content

Content-Type returned by JSON is not application/json when used in special middlewares #78

Description

@aharbis

💡 The feature or bug you are proposing

Using bunrouter.JSON in handlers passed to either WithNotFoundHandler or WithMethodNotAllowedHandler results in application/text Content-Type header.

📄 The description of the bug or the logic behind your proposal

Constructing my router like this:

router := bunrouter.New(
	bunrouter.WithMiddleware(reqLogMiddleware),
	bunrouter.WithMiddleware(errorHandlerMiddleware),
	bunrouter.WithNotFoundHandler(notFoundHandler),
	bunrouter.WithMethodNotAllowedHandler(methodNotAllowedHandler),
)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions