iamsarki
Minnow
Posts: 16
Member is Online
|
Post by iamsarki on Jan 9, 2024 13:50:03 GMT
Hi, In case a client sends a request with an 'accept' header which has a value that I don't support (for example 'application/xml' when requesting a json) What should I do?
Should I send back a "406 Not Acceptable" response?
The redfish specification (Table 6 — Request headers) says this for the 'Accept-Encoding' header but says nothing for the 'Accept' header.
Also, it lists the values that the service should support, but should the service also support more complex ones like 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' ?
|
|
|
Post by mraineri on Jan 9, 2024 13:57:02 GMT
Yes, you can use 406 if the client provides an Accept header where the service cannot satisfy any of the requested formats. We do call that out in the "Status codes" clause:
> Accept header was specified in the request and the resource identified by this request cannot generate a representation that corresponds to one of the media types in the Accept header.
You are certainly allowed to support more complex ones; the specification gives the minimum set of what is required, but you're free to go beyond that.
|
|
iamsarki
Minnow
Posts: 16
Member is Online
|
Post by iamsarki on Jan 9, 2024 14:05:19 GMT
Thanks, would sending a response with a "default" format be considered wrong? From mdn (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406): "In practice, this error is very rarely used. Instead of responding using this error code, which would be cryptic for the end user and difficult to fix, servers ignore the relevant header and serve an actual page to the user. It is assumed that even if the user won't be completely happy, they will prefer this to an error code."
|
|