When an HTTP client program (such as a browser) sends a request to a server, it must specify the request type (typically GET or POST). If necessary, the client program can also choose to send additional request headers. Most request headers are not mandatory, but for POST requests, the Content-Length header must be included. Below is an overview of some of the most common HTTP request headers (HttpServletRequest):
Accept:
The MIME types that the browser can accept.
Accept-Charset:
The character sets that the browser can accept.
Accept-Encoding:
The data encoding methods that the browser can decode, such as gzip. Servlets can return HTML pages encoded with gzip to browsers that support it. In many cases, this can reduce download times by a factor of 5 to 10.
Accept-Language:
The preferred language(s) of the browser, used when the server can provide more than one language version.
Authorization:
Authorization information, typically included in response to a WWW-Authenticate header sent by the server.
Connection:
Indicates whether a persistent connection is required. If the Servlet sees a value of "Keep-Alive" here or detects that the request uses HTTP 1.1 (which defaults to persistent connections), it can leverage the advantages of persistent connections. When the page contains multiple elements (such as applets or images), this can significantly reduce download times. To achieve this, the Servlet needs to send a Content-Length header in its response. The simplest way to implement this is to first write the content to a ByteArrayOutputStream and then calculate its size before writing it out formally.
Content-Length:
Indicates the length of the request message body.
Cookie:
One of the most important request headers.
From:
The email address of the request sender, used by some special web client programs; browsers do not use it.
Host:
The host and port from the initial URL.
If-Modified-Since:
Returns the requested content only if it has been modified after the specified date; otherwise, returns a 304 "Not Modified" response.
Pragma:
Specifying a value of "no-cache" indicates that the server must return a refreshed document, even if it is a proxy server and already has a local copy of the page.
Referer:
Contains a URL representing the page from which the user accessed the currently requested page.
User-Agent:
The browser type, which is very useful if the content returned by the Servlet is related to the browser type.
UA-Pixels, UA-Color, UA-OS, UA-CPU:
Non-standard request headers sent by certain versions of Internet Explorer, indicating screen size, color depth, operating system, and CPU type.