HTTP Headers

Quick Reference

Updated: 2008-02-25 (mca)

Considerations

When dealing with Cross-Site Requests (CSRs), the following needs to be considered for handling HTTP Headers:

  1. Can the header be sent by the client? Send
  2. Can the header be accepted by the client? Recv
  3. Can the header be edited by the client? Edit

For example, consider the case of handling the cookie and set-cookie headers. In the least restrictive case, clients can recieve the set-cookie header from servers. They can also send the cookie header back to the server. Clients also allow script authors to edit the contents of the cookie header directly:

// via header
XMLHttpRequest.setRequestHeader('cookie','mysecret=12345;');
// via the cookie object
document.cookie = 'mysecret=12345; expires=Thu, 2 Aug 2009 15:30:00 UTC; path=/'

In a more restrictive case, the set-cookie and cookie headers would be allowed, but script authors could not change the content of the cookie header. The client could only read cookie values from the header, but not write them. In the most restrictive case, clients could not even receive the cookie or set-cookie headers from the server or send the cookie header to the server.

Finally, there is the matter of how to handle attempts to 'break the rules.' One possibility is to ignore the attempt. For example, in the case where cookies can be read but not written, the client could just silently ignore attempts to write a cookie value. Or the client could throw an error and stop the processing of the request. For example, if the server sends a set-cookie command to the client, a SECURITY_ERR would be thrown.

Examples of HTTP Headers that the XMLHttpRequest client can recieve, but not edit are Content-Length and Date.

Common HTTP Headers

Accept

RequestRFC2616SendRecvEdit

Used to tell the server what media type(s) are preferred by the client.

Accept-Charset

RequestRFC2616RecvXHRr

Used to tell the server what character sets are preferred by the client.

Accept-Encoding

RequestRFC2616RecvXHRr

Used to tell the server the encodings preferred by the client.

Accept-Language

RequestRFC2616SendRecvEdit

Used to tell the server which natural languages are preferred by the client.

Accept-Ranges

ResponseRFC2616Recv

Used by the server to indicate it is capable of supporting the Accept-Range header form the client. can be set to bytes or none.

Age

ResponseRFC2616Recv

Indicates the server estimatation of the age (in seconds) of the requested resource.

Allow

EntityRFC2616Recv

Used by the server to indicate which HTTP Methods are supported for this URI. Usually in response to a GET to the target URI using the OPTIONS method.

Authentication-Info

ResponseRFC2616Recv

Sent by the server as the final step in the Digest authentication conversation with the client.

Authorization

RequestRFC2616SendEdit

The security token that represents the authenticated client.

Cache-Control

GeneralRFC2616SendRecvEdit

Used to control caching behavior. The value of this header depends on whether it is sent in a request (by the client) or in a response (by the server).

  • Request Directives
    1. no-cache
    2. no-store
    3. max-age
    4. max-stale
    5. min-fresh
    6. no-transform
    7. only-if-cached
    8. cache-extension
  • Response Directives
    1. public
    2. private
    3. no-cache
    4. no-store
    5. no-transform
    6. must-revalidate
    7. proxy-revalidate
    8. max-age
    9. s-maxage
    10. cache-extension

Connection

GeneralRFC2616HbHXHRr

Used to manage the connection type. Can be Keep-Alive or Close. Also possible: Upgrade.

Content-Disposition

ResponseRFC2616Recv

Used by the server to suggest the filename the client should use when the client wants to store the resource locally.

Content-Encoding

EntityRFC2616RecvXHRr

Used to indicate any special encoding of the body of the request. Common values are: 1) compress; 2) deflate; and 3) gzip. Clients indicate the encoding preferences using the Accept-Encoding header.

Content-Language

EntityRFC2616Recv

Indicates the language used in the body of the request. Clients indicate the language preferences using the Accept-Language header.

Content-Length

EntityRFC2616SendRecvXHRr

The length of the entity body in bytes.

Content-Location

EntityRFC2616Recv

Used to indicate the URL of the returned resource when it does not match the requested resource.

Content-MD5

EntityRFC2616SendRecvEdit

Used to ensure the contents of the message arrived safely. For example, the Server would calculate the MD5 (Message Digest 5) hash of the message body and convert it into Base-64 encoding to create a single string that represents the message body. Upon receipt, the client would do the same and compare the two strings. If they match, the message body arrived without alterations.

Content-Range

EntityRFC2616Recv

Used by a server to indicate it is only returning a portion of the requested resource. Usually in response to the Range request header.

Content-Type

EntityRFC2616SendRecvEdit

Used to indicate the type of resource being transmitted. Usually one of the types maintained by the IANA.

Cookie

RequestRFC2109SendEdit

A collection of state data passed between server and client. Created by the client in response to the Set-Cookie header (see Response headers).

Date

GeneralRFC2616RecvXHRr

The date of the request or response.

ETag

ResponseRFC2616SendRecvEdit

The server's 'version' value of the resource. Usually a hash of the body of the resource. Used for caching and as a way to validate updates (PUT/POST).

Expect

RequestRFC2616SendEditHbHXHRr

One or more restrictions that the server MUST meet in order to complete the request. This is a Hop-by-Hop header (any proxy MUST return 417 if that proxy cannot meet the request).

Expires

EntityRFC2616Recv

Used to indicate the date and time this resource will be considered invalid. Sent by the Server to tell the client the last date/time the resource can be cached locally.

From

RequestRFC2616SendRecvEdit

The email address of the client user.

Host

RequestRFC2616SendRecvXHRr

Specifies the Internet host and port number of the resource being requested.

If-Match

RequestRFC2616SendRecvEdit

Client's copy of the server's ETag. Used in caching and to validate the version/copy of the resource. Usually a hash of the resource body. If the value matches the one on the server, the request will be executed by the server.

If-Modified-Since

RequestRFC2616SendEdit

Client's copy of the Date header sent by the server. Used in caching and to validate the version/copy of the resource.

If-None-Match

RequestRFC2616SendEdit

Client's copy of the server's ETag. Used in caching and to validate the version/copy of the resource. Usually a hash of the resource body. If the value *does not* match the one on the server, the request will be executed by the server.

If-Range

RequestRFC2616SendEdit

Used along with the Range Header. Can be a copy of the server's ETag or Date. If this value matches the one on the server, the server *will* send the requested Range of the resource.

If-Unmodified-Since

RequestRFC2616SendEdit

A copy of the server's Date header. If this value matches the one on the server, the server will execute the request. Usually used to make sure the resource on the server has not changed before the client's POST or PUT action is executed.

Keep-Alive

GeneralRFC2616SendRecvHbHXHRr

Can be used to indicate to both client and server how long the connection can be kept open. Obsoleted in RFC2616.

Last-Modified

EntityRFC2616Recv

Used to indicate the date/time the resource was last modified.

Location

ResponseRFC2616Recv

The URI to use to get the most recent copy of the requested resource. Usually used during a 'redirect' action.

Max-Forwards

RequestRFC2616SendEdit

Used by clients to limit the number of intermediaries (proxies) through which the reqest may be passed. Rarely used, exception for diagnosing proxie issues.

Pragma

GeneralRFC2616SendRecvEdit

Used to control caching behavior for HTTP 1.0 servers. Can only be set to no-cache.

Proxy-Authentication

ResponseRFC2616HbHXHRr

Same as the WWW-Authenticate header, except sent by proxy/intermediate machines to authenticate against the server.

Proxy-Authorization

RequestRFC2616HbHXHRr

Same as the Authorization header, but in response to a proxy's Proxy-Authenticate header.

Range

RequestRFC2616SendEdit

Used by the client to tell the server to send just a byte range of the resource on the server.

Referer

RequestRFC2616SendXHRr

Used by the client to indicate the current location from which the request is coming.

Refresh

ResponseRFC2616Recv

Can be used by the server to tell the client to periodically send a GET request back to the server. The same as the htp-equiv="refresh" HTML meta tag.

Retry-After

ResponseRFC2616Recv

Used by the server, during a 503 (Service Unavailable) error, to tell the client how long to wait before trying the request again.

Server

ResponseRFC2616Recv

Identity string for this server.

Set-Cookie

ResponseRFC2109Recv

Used by the server to tell the client to store some state information to return to the server with subsequent requests.

TE

RequestRFC2616SendEditHbHXHRr

Transfer encoding indicator. Usually used to indicate the client can support chunked transfers.

Trailer

GeneralRFC2616SendRecvEditHbHXHRr

Allows sending headers mixed in with the resource body. Used with chunked transfers.

Transfer-Encoding

GeneralRFC2616SendRecvEditHbH

Used to indicate details on the transfer of the body. Only one valid value right now: chunked.

Upgrade

GeneralRFC2616RecvHbHXHRr

Used to try to negotiate a protocol change between client and server.

User-Agent

RequestRFC2616Send

The identity string for this client.

Vary

ResponseRFC2616Recv

Instructions to any intermediates/proxies which header(s) to use when determining how to fulfil the request from caches.

Via

GeneralRFC2616RecvXHRr

Used by proxy/intermediaries to identify themselves in the communication stream. Similar to the Server and User-Agent headers.

Warning

GeneralRFC2616Recv

Relays adescriptionitional information, usually sent by the server to the client to indicate problems with the caching.

WWW-Authenticate

ResponseRFC2616Recv

Used by the server to indicate the client must first send authentication credentials in order to complete the request.

References

  1. [RFC2109]HTTP State Management Mechanism (Feb-1997)
  2. [RFC2616]Hypertext Transfer Protocol -- HTTP/1.1 (Jun-1999)
  3. [XMLHttpRequest]The XMLHttpRequest Object (Draft Oct-2007)