ninja icon indicating copy to clipboard operation
ninja copied to clipboard

Accept header not parsed in standard way, causing incorrect type of response to be issued

Open omervk opened this issue 9 years ago • 2 comments

This is a huge issue in how the accepted media type is selected. If text/html appears anywhere in the value, it is preferred, even if that's not the case!

This means that the value application/json; q=1.0, text/html; q=0.9, */*; q=0.1 in Accept, which means "give me JSON first, HTML if that doesn't exist and anything else if you have neither" is interpreted by Ninja as "give me HTML".

According to the code in AbstractContext.getAcceptContentType, the following is the order in which the media type is selected, without the user-specified order:

  1. HTML
  2. XML
  3. JSON
  4. Plain Text
  5. application/octet-stream
  6. If none of the above, HTML

omervk avatar Mar 15 '16 12:03 omervk

Hi @omervk,

I haven't explored the content negotiation features of Ninja yet, but I think its a bit less straight forward than this single method. I think Ninja has another part of the code that helps pick the type your result renders to. http://www.ninjaframework.org/documentation/content_negotiation.html

Ninja is a community effort, so if you wanted to submit a PR that enhances/improves/fixes it, I'd be happy to take a look.

jjlauer avatar Mar 15 '16 17:03 jjlauer

@jjlauer,

Yes, I've seen this part of Ninja and have placed my comments in another issue, #487.

I'll see if I can contribute code for any of the three issues I opened. :+1:

omervk avatar Mar 16 '16 06:03 omervk