Appendix B. Common HTTP Headers

Here we look at a series of often-used headers, whether they are request or response headers, and how they can be used.

HeaderRequestResponseNotes

Accept

yes

This shows the formats, with an indication of preference, that the requesting client can understand. Closely related are the additional headers Accept-Charset, Accept-Encoding, and Accept-Language.

Authorization

yes

This is free-form information to prove a user’s identity. This is used in basic authentication, digest authentication, OAuth, and so on; each has their own format of exactly what goes in the header.

Cookie

yes

Cookies are key/value pairs sent with each request, separated by a semicolon. This is the sister header to Set-Cookie.

Content-Length

yes

yes

Any request or response with body content should also have the Content-Length in bytes in the header; often your HTTP library will calculate this for you.

Content-Type

yes

yes

Any request or response with body content should include the Content-Type header to provide information about the format of that body content. As with the Accept headers, Content-Encoding and Content-Language may also be sent to give information about the format of the content.

ETag

yes

This is an identifier for the version of the resource that is being returned. If the client caches the resource, this information can be used with If-None-Match to work out whether a resource has been updated or if the previous version can be used.

If-Modified-Since and If-None-Match

yes

This informs ...

Get PHP Web Services 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.