GarethJ
GarethJ

Reputation: 6606

Is using Content-Language header appropriate to localize a side effect of an HTTP POST?

I'm designing a REST API where content in the form of HTML is being posted to an endpoint. I'm using the lang attribute in the HTML to specify the language of the document or sections thereof. That is working nicely.

However, the content can be posted to a 'default' pseudo-resource, whose user-visible name is automatically generated, and thus needs to be localized. I need a way to specify which language to use when creating this name on the fly as a side effect of a first POST to the default section. Unfortunately, I'm not able to derive my user's preferred language from their login profile.

Does it seem reasonable to use the Content-Language header to specify this? There could be a clash with the languages(s) of the actual HTML content, and it is not strictly the language of the entity being POSTed.

Would it even make sense to treat the side effect as a type of 'response' and thus use Accept-Language instead?

Upvotes: 0

Views: 661

Answers (1)

Filip
Filip

Reputation: 3094

A content-language is subject of content negotiation as well as content-type. Browsers automatically generate Accept-Language values from user's settings. e.g.

Accept-Language: en-US,en;q=0.8,cs;q=0.6

so you will only get user's language preference and that's all.

You can also use content-language (note that multiple languages are supported, e.g. content-language: en, de) to denote language(s) of content.

I would discourage you from giving users an ability to affect final URLs, but I guess that you are doing it because of SEO, right? If yes, common practice is to use something like mod_rewrite to strip dynamically generated 'nice URL' e.g.

http://example.org/some really nice name to be indexed/232323 to http://example.org/?id=232323

Add your question: There can be probably only clash with built-in browsers translators as I'm not aware of any other component utilizing Content-Language.

Upvotes: 1

Related Questions