openwhisk-apigateway icon indicating copy to clipboard operation
openwhisk-apigateway copied to clipboard

API GW should adhere to "Accept" header dictates as much as possible

Open mdeuser opened this issue 6 years ago • 3 comments

Here is one specific example, although other scenarios likely have the same issue.

  1. Create an API that is configured with "Require applications to authenticate via API key" enabled.
  2. Invoke the API using curl, but specifying the "Accept" media type as something besides application/json
  3. A 401 is returns with a JSON body and "Content-Type" value of application/json
>curl https://service.us.apiconnect.ibmcloud.com/gws/apigateway/api/API-UNIQUE-ID/API-PATH -H "Accept: application/xml"

{"status":401,"message":"Error: Unauthorized"}

mdeuser avatar Feb 28 '18 16:02 mdeuser

So, in your scenario, let's say you pass an Accept header of text/html. If an API key is required, the gateway responds with 401, but what Content-Type is the response body?

PRs are welcome, btw ;-)

mhamann avatar Feb 28 '18 19:02 mhamann

I guess the server might be able to support a few "standard" media types and respond with the one that matches the request Accept header. If a server is unable to adhere to the requests Accept set of media types, should it return a 406?

mdeuser avatar Feb 28 '18 20:02 mdeuser

I think 406 isn't terribly useful, since we don't know exactly what types are allowable and it would be preferable to tell the caller why the call failed even if it's in a format they didn't ask for. Since we'd set the Content-Type to whatever is being returned (which would be application/json by default), then the caller should be prepared to handle that case.

mhamann avatar Feb 28 '18 20:02 mhamann