Java Reference
In-Depth Information
those types matches the formats the server can offer, anything can be passed back to the cli-
ent.
Language Negotiation
HTTP Content Negotiation also has a simple protocol for negotiating the desired human lan-
guage of the data sent back to the client. Clients use the
Accept-Language
header to specify
which human language they would like to receive. For example:
GET http://example.com/stuff
Accept-Language: en-us, es, fr
Here, the client is asking for a response in English, Spanish, or French. The
Accept-Lan-
guage
header uses a coded format. Two digits represent a language identified by the ISO-639
US English.
The
Accept-Language
header also supports preference qualifiers:
GET http://example.com/stuff
Accept-Language: fr;q=1.0, es;q=1.0, en=0.1
Here, the client prefers French or Spanish, but would accept English as the default transla-
tion.
Clients and servers use the
Content-Language
header to specify the human language for
message body translation.
Encoding Negotiation
Clients can also negotiate the encoding of a message body. To save on network bandwidth,
encodings are generally used to compress messages before they are sent. The most common
algorithm for encoding is GZIP compression. Clients use the
Accept-Encoding
header to
specify which encodings they support. For example:
GET http://example.com/stuff
Accept-Encoding: gzip, deflate
Here, the client is saying that it wants its response either compressed using GZIP or uncom-
pressed (
deflate
).
The
Accept-Encoding
header also supports preference qualifiers: