Skip to content

Add HttpHeaders getter and setter for Content-Language [SPR-14536] #19105

Closed

Description

@spring-projects-issues

Daniel Fernández opened SPR-14536 and commented

Now that content negotiation is in place at the View/ViewResolver mechanism and therefore View implementations don't need to manually create the Content-Type HTTP header, it would be nice to have a similar mechanism that avoided the manual creation of the Content-Language header.

The current code at the reactive version of ThymeleafView (see here) does something like:

final HttpHeaders responseHeaders = exchange.getResponse().getHeaders();
if (templateLocale != null) {
    responseHeaders.set("Content-Language", templateLocale.toString());
}

However, in Spring MVC thanks to the HttpServletResponse#setLocale(Locale) method, all it had to do is:

response.setLocale(templateLocale);

It's not that creating this header is extremely ugly code, but anyway IMHO it would be great if Spring Reactive included some kind of higher-level mechanism for setting this Content-Language that kept View implementations from having to create it manually.


Affects: 5.0 M1

Issue Links:

Referenced from: commits 36da299

Activity

  1. spring-projects-issues commented on Nov 7, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Rossen Stoyanchev I think I can take care of this one if you don't mind.

  2. spring-projects-issues commented on Dec 9, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    It might make sense to start with support in HttpHeaders for Accept-Language and Content-Language accepting and returning Locale or List<Locale> in the case of Accept-Language.

    That might even be all that needs to be done for this ticket since setContentLanguage can check the input locale for null.

  3. spring-projects-issues commented on Dec 15, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Fixed by this commit. See also #19591 that adds Accept-Language getter and setter.

  4. added
    type: enhancement
    in: web
    on Jan 11, 2019
  5. added this to the 5.0 M4 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions