Patch #26709

Use correct http status codes

Added by Pavel Rosický almost 2 years ago. Updated over 1 year ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:


Category:REST API
Target version:4.1.0


1/ redmine ignores accept headers and jquery dataType attribute

The Accept request-header field can be used to specify certain media types which are acceptable for the response.

If no Accept header field is present, then it is assumed that the client accepts all media types. If an Accept header field is present, and if the server cannot send a response which is acceptable according to the combined Accept field value, then the server SHOULD send a 406 (not acceptable) response.

The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback)


curl -v -H
-> 200 + json OK!

curl -v -H "Accept: application/json"
-> 500 no builder for format

expected (with patch)
-> 200 + json output

in some cases html is returned even if json was requested

2/ 406 error raises exception

curl -v
-> 406 + exception ActionController::UnknownFormat

expected (with patch)
-> 406 no exception

3/ csrf protection - useful to avoid exceptions because of site-scanner bots

curl -v -H "Accept: text/javascript"
-> 422 + exception ActionController::InvalidCrossOriginRequest: Security warning: an embedded <script> tag on another site requested protected JavaScript.

-> 400 - no exception

builders.rb.patch Magnifier - no builder for format (501 Bytes) Pavel Rosický, 2017-08-17 01:26

application_controller.rb.patch Magnifier - ActionController::UnknownFormat & CSRF (1.11 KB) Pavel Rosický, 2017-08-17 01:26

api_test.rb.patch Magnifier - + spec (1.22 KB) Pavel Rosický, 2017-09-15 22:43


#1 Updated by Toshi MARUYAMA almost 2 years ago

Could you add tests?

#2 Updated by Pavel Rosický almost 2 years ago

builders.rb.patch without a patch fails:

Expected response to be a <422: Unprocessable Entity>, but was a <500: Internal Server Error>.
Expected: 422
  Actual: 500

Expected response to be a <200: ok>, but was a <500: Internal Server Error>.
Expected: 200
  Actual: 500

application_controller.rb.patch this isn't worth fixing, it affects only logs so I can't detect it in tests anyway

#3 Updated by Toshi MARUYAMA over 1 year ago

  • Target version set to 4.1.0

Also available in: Atom PDF