Skip to content

Instantly share code, notes, and snippets.

@rubenclopez
Last active January 3, 2016 04:19
Show Gist options
  • Save rubenclopez/8408526 to your computer and use it in GitHub Desktop.
Save rubenclopez/8408526 to your computer and use it in GitHub Desktop.
Request Headers
Request Headers
---------------
Request headers let the client specify additional information to the server about the requested representation of a resource. This list is by no means complete, but here are some common request headers, with examples that a client may specify:
• Accept: text/plain, text/html—This tells the server that the client is looking for a plain-text or HTML representation of the resource. Other options could be application/json, text/javascript, application/xml, text/xml, image/jpeg, and countless others.
• Accept-Encoding: compress, gzip—This header tells the server whether the client can take a gzip or compressed response.
• User-Agent: pauldix-service-client/1.0—In most cases, the user agent field isn’t required. However, some servers reject requests that don’t specify a user agent of some kind. It’s generally part of being a good Internet citizen to specify a user agent that server administrators can find information on.
• Accept-Language: en—This header tells the server what language the resource should be returned in. This example requests English.
• If-Modified-Since: Tue, 30 Jun 2009 08:30:31 GMT—This header tells the server that the client has a version of the resource that was last generated at 8:30 AM on June 30. If the server has a newer version, it should return that in the response. If that version is the latest, then the server should return an empty response body with a 304 Not Modified response code. This is one piece of the caching mechanisms that is built into HTTP.
• If-None-Match: "sdfzlkjsd"—This header is another way for the client to tell the server that it has a cached version of a resource. The supplied string matches up with an ETag in the response header. If the client-supplied ETag matches that of the most current version of the requested resource, the server should return an empty response body with a 304 Not Modified response code. Otherwise, the server should return the latest version of the requested resource.
• Content-Type: application/x-www-form-urlencoded—The content type field is used in POST and PUT requests to specify to the server the format of the request body. The example here is for a form POST. Two other common examples are application/json and application/xml.
• Content-Length: 1274—This tells the server the length of the request body, in bytes.
• Cookie: user_id=PaulDix; sort=date—Cookies are set in the request header. This is a list of name/value pairs separated by semicolons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment