Sunday, June 8, 2014

HTTP The Definitive Guide (Content Negotiation and Transcoding)

Content Negotiation and Transcoding
Content-Negotiation Techniques
There are three distinct methods for deciding which page at a server is the right one for a client: present the choice to the client, decide automatically at the server, or ask an intermediary to select.

Client-Driven Negotiation
The easiest thing for a server to do when it receives a client request is to send back a response listing the available pages and let the client decide which one it wants to see.

Server-Driven Negotiation
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.
Server-Driven Negotiation


Content-Negotiation Headers

Content-Negotiation Header Quality Values

Varying on Other Headers
Servers also can attempt to match up responses with other client request headers, such as User-Agent.
the Vary header tells caches (and clients, and any downstream proxies) which headers the server is using to determine the best version of the response to send.

Content Negotiation on Apache
There are two ways to enable content negotiation:

  • In the web site directory, create a type-map file for each URI in the web site that has variants. The type-map file lists all the variants and the content-negotiation headers to which they correspond.
  • Enable the MultiViews directive, which causes Apache to create type-map files for the directory automatically.

Using type-map files
Using MultiViews

Server-Side Extensions

Transparent Negotiation
Transparent negotiation seeks to move the load of server-driven negotiation away from the server, while minimizing message exchanges with the client by having an intermediary proxy negotiate on behalf of the client.
Servers send Vary headers in their responses to tell intermediaries what request headers they use for content
negotiation.

Caching and Alternates
The Vary Header

If a server’s Vary header looked like this, the huge number of different User-Agent and Cookie values could generate many variants:
Vary: User-Agent, Cookie
A cache would have to store each document version corresponding to each variant. When the cache does a lookup, it first does content matching with the content-negotiation headers, then matches the request’s variant with cached variants. If there is no match, the cache fetches the document from the origin server.

Transcoding

There are three categories of transcoding: format conversion, information synthesis, and content injection.


Format Conversion
Information Synthesis
Content Injection
Examples of contentinjection transcodings are automatic ad generators and user-tracking systems.

Transcoding Versus Static Pregeneration
Next Steps
















































No comments:

Post a Comment