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

MockHttpServletResponse doesn't propagate Content-Language response header

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 5.0.9
    • Fix Version/s: 5.0.10, 5.1.1
    • Component/s: Test
    • Labels:
    • Last commented by a User:
      true

      Description

      When trying to test our language fallback scenario using spring-test, I've noticed that the following scenario is failing, while it works just fine when reproduced with curl (the actual content of the test has been replaced due to the proprietary nature of the project):

       

      mockMvc.perform(post(SOME_URL)
           .header(HttpHeaders.ACCEPT_LANGUAGE, NOT_SUPPORTED_LANGUAGE)
           .content(serializeRequest()))
           .andExpect(header().string(HttpHeaders.CONTENT_LANGUAGE, FALLBACK_LANGUAGE));

       
      As I ventured on to find the cuplrit I've noticed that this is handled as a special case of a header in MockHttpServletResponse:

       

      https://github.com/spring-projects/spring-framework/blob/v5.0.9.RELEASE/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java#L592

       
      After the locale is set, unlike in the first two if cases, the header is not actually added to the response, causing failure in the tests. For reference this is how the header is set in the controller:

       

      return ResponseEntity
          .status(HttpStatus.OK)
          .header(HttpHeaders.CONTENT_LANGUAGE, language)
          .body(serializedDto);

      I would expect the header to actually be set, unless there's something I've missed when browsing through the mechanism - if so, I would love if you could point me to the relevant resources to understand this better.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              mszymborski Michał Szymborski
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 31 weeks, 2 days ago