Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16251

Breaking change in MVC: Accept handling is now more strict


    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Complete
    • Affects Version/s: 5.0.2
    • Fix Version/s: 5.0.3
    • Component/s: Web
    • Labels:
    • Last commented by a User:



      • MVC controller with a ResponseEntity<?> object.
      • Client sends Accept: application/json
      • Server responds with: application/what.ever+json in the ResponseEntity's headers.

      This was seemingly OK with 5.0.1 and before. After upgrading to 5.0.2, it forces to return 406, despite the ResponseEntity saying otherwise.

      The commit that caused it is:

      The RFC says:

      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.*

      Please note that it says SHOULD, and not MUST:

      3. SHOULD   This word, or the adjective "RECOMMENDED", mean that there
         may exist valid reasons in particular circumstances to ignore a
         particular item, but the full implications must be understood and
         carefully weighed before choosing a different course.

      So, a patch release of Spring seems to be enforcing a more strict behaviour, disallowing something allowed (albeit not recommended) by RFC, and breaking existing applications.

      A workaround is possible by having a nasty servlet filter that manipulates headers, and adds application/*+json when application/json is in Accept... but, considering this is a patch release, I suggest you consider this behaviour change a bug, as it has backward-compatibility implications, and try not to break acceptable flows.


          Issue Links



              • Assignee:
                rstoya05-aop Rossen Stoyanchev
                flozano Francisco Lozano
                Last updater:
                Spring Issuemaster
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created:
                  Days since last comment:
                  35 weeks, 4 days ago