Server-Driven Negotiation

Client-driven negotiation has several drawbacks, as discussed in the previous section. Most of these drawbacks center around the increased communication between the client and server to decide on the best page in response to a request. One way to reduce this extra communication is to let the server decide which page to send back—but to do this, the client must send enough information about its preferences to allow the server to make an informed decision. The server gets this information from the client’s request headers.

There are two mechanisms that HTTP servers use to evaluate the proper response to send to a client:

  • Examining the set of content-negotiation headers. The server looks at the client’s Accept headers and tries to match them with corresponding response headers.

  • Varying on other (non-content-negotiation) headers. For example, the server could send responses based on the client’s User-Agent header.

These two mechanisms are explained in more detail in the following sections.

Content-Negotiation Headers

Clients may send their preference information using the set of HTTP headers listed in Table 17-2.

Table 17-2. Accept headers

Header

Description

Accept

Used to tell the server what media types are okay to send

Accept-Language

Used to tell the server what languages are okay to send

Accept-Charset

Used to tell the server what charsets are okay to send

Accept-Encoding

Used to tell the server what encodings are okay to send

Notice how similar ...

Get HTTP: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.