roaster icon indicating copy to clipboard operation
roaster copied to clipboard

A request with an unsupported media type should return 415

Open dariok opened this issue 2 months ago • 0 comments

Currently, on POST at least, if a "Content-Type" header is sent with a type that is not declared in the spec, a 400 Bad Request is returned (from: body.xqm:130)

This should instead be a 415 Unsupported Media Type, ideally with an Accept: header containing a white space separated list of the media types defined in the spec for this method and path.

--

Request:

POST http://localhost:8080/exist/apps/project/endpoint
Content-Type: application/json

{ "test": "test" }

Current reply:

HTTP/1.1 400 Bad Request
Connection: close
Date: Sat, 25 Oct 2025 10:17:02 GMT
X-XQuery-Cached: true
Content-Type: application/json
Server: Jetty(9.4.57.v20241219)

{
   …,
  "module": "/db/system/repo/roaster-1.11.0/content/body.xqm",
  "line": 130,
  "description": "Body with media-type 'application/json' is not allowed"
}

improved reply:

HTTP/1.1 415 Unsuported Media Type
…
Accept: application/xml text/plain

[perhaps error JSON]

Cf. https://httpwg.org/specs/rfc9110.html#status.415 and https://httpwg.org/specs/rfc9110.html#field.accept


Edit: affected version: Roaster 1.11.0


Edit:

  • Status 400 could be considered a better fit if a Content-Type is absent from a PUT or POST.
  • if the encoding is wrong, the Accept-Encoding header should be sent indicating the supported encodings.

dariok avatar Oct 25 '25 13:10 dariok