Showing posts with label HTTP Response Headers. Show all posts
Showing posts with label HTTP Response Headers. Show all posts

18 Feb 2014

HTTP Response Headers Part II (Methods)

setHeader(String headerName, String headerValue)

This method sets the response header with the designated name to the given value.


setDateHeader(String header, long milliseconds)

This method saves you the trouble of translating a Java date in milliseconds since 1970 (as returned by System.currentTimeMillis, Date.getTime, or Calendar.getTimeInMillis) into a GMT time string. 


setIntHeader(String header, int headerValue)

This method spares you the minor inconvenience of converting an int to a String before inserting it into a header.


setContentType(String mimeType)

This method sets the Content-Type header and is used by the majority of servlets.


setContentLength(int length)

This method sets the Content-Length header, which is useful if the browser supports persistent (keep-alive) HTTP connections.


addCookie(Cookie c)

This method inserts a cookie into the Set-Cookie header. There is no corresponding setCookie method, since it is normal to have multiple Set-Cookie lines. 


sendRedirect(String address)

The sendRedirect method sets the Location header as well as setting the status code to 302.

17 Feb 2014

HTTP Response Headers-Part I (Headers Only)


Accept

This header specifies the MIME types that the browser or other clients can handle.

Accept-Charset

This header indicates the character sets (e.g., ISO-8859-1) the browser can use.

Accept-Encoding

This header designates the types of encodings that the client knows how to handle.
  • public
    Document is cacheable, even if normal rules (e.g., for password-protected pages) indicate that it shouldn't be.
  • private: 
     Document is for a single user and can only be stored in private (nonshared) caches.
  • no-cache: 
    Document should never be cached (i.e., used to satisfy a later request). The server can also specify "no-cache="header1,header2,...,headerN"" to stipulate the headers that should be omitted if a cached response is later used. 
  • No store:
     Document should never be cached and should not even be stored in a temporary location on disk. This header is intended to prevent inadvertent copies of sensitive information.

Connection

A value of close for this response header instructs the browser not to use persistent HTTP connections.

Content-Disposition

The Content-Disposition header lets you request that the browser ask the user to save the response to disk in a file of the given name. This header is particularly useful when you send the client non-HTML responses (e.g., Excel spreadsheets, JPEG images).

Content-Encoding

This header indicates the way in which the page was encoded during transmission. The browser should reverse the encoding before deciding what to do with the document.

Content-Language

The Content-Language header signifies the language in which the document is written.

 

Content-Length

This header indicates the number of bytes in the response. This information is needed only if the browser is using a persistent (keep-alive) HTTP connection. 

 

Content-Type

The Content-Type header gives the MIME (Multipurpose Internet Mail Extension) type of the response document. Setting this header is so common that there is a special method in HttpServletResponse for it: setContentType. MIME types are of the form maintype/subtype for officially registered types and of the form maintype/x-subtype for unregistered types.

Expires

This header stipulates the time at which the content should be considered out-of-date and thus no longer be cached. A servlet might use this header for a document that changes relatively frequently, to prevent the browser from displaying a stale cached value. 

Last-Modified

This very useful header indicates when the document was last changed. The client can then cache the document and supply a date by an If-Modified-Since request header in later requests.

Location

This header, which should be included with all responses that have a status code in the 300s, notifies the browser of the document address. The browser automatically reconnects to this location and retrieves the new document. This header is usually set indirectly, along with a 302 status code, by the sendRedirect method of HttpServletResponse.

 

 Pragma

Supplying this header with a value of no-cache instructs HTTP 1.0 clients not to cache the document. However, support for this header was inconsistent with HTTP 1.0 browsers.

Refresh

This header indicates how soon (in seconds) the browser should ask for an updated page.

Retry-After

This header can be used in conjunction with a 503 (Service Unavailable) response to tell the client how soon it can repeat its request.

Set-Cookie

The Set-Cookie header specifies a cookie associated with the page. Each cookie requires a separate Set-Cookie header. Servlets should not use response.setHeader("Set-Cookie", ...) but instead should use the special-purpose addCookie method of HttpServletResponse.

WWW-Authenticate

This header is always included with a 401 (Unauthorized) status code. It tells the browser what authorization type and realm the client should supply in its Authorization header.

Comments

© 2013-2016 ITTechnocrates. All rights resevered. Developed by Bhavya Mehta