HTTP response header information


Release date:2024-02-27 Update date:2024-02-28 Editor:admin View counts:65

Label:

HTTP response header information

The HTTP request header provides information about the request, response, or other sending entity.

In this section, we will introduce the HTTP response header information in detail.

Answering head

Description

Allow

Which request methods (such as GET, POST, etc.) are supported by the server.

Content-Encoding

The Encode method of the document. The content type specified by the Content-Type header can be obtained only after decoding. Using gzip to compress documents can significantly reduce the download time of HTML documents. Java’s GZIPOutputStream can easily do gzip compression, but only Netscape on Unix and IE 4 and IE 5 on Windows support it. Therefore, Servlet should check whether the browser supports gzip by looking at the Accept-Encoding header (that is, request.getHeader (“Accept-Encoding”), returning gzip-compressed HTML pages for browsers that support gzip, and normal pages for other browsers.

Content-Length

Represents the content length. This data is needed only if the browser uses a persistent HTTP connection. If you want to take advantage of persistent connections, you can write the output document to ByteArrayOutputStream, check its size when finished, put this value in the Content-Length header, and finally send the content through byteArrayStream.writeTo (response.getOutputStream ().

Content-Type

Indicates what MIME type the subsequent document belongs to. Servlet defaults to text/plain, but usually needs to be explicitly specified as text/html. Because Content-Type is often set up, HttpServletResponse provides a special method, setContentType.

Date

The current GMT time. You can use setDateHeader to set this header to avoid the hassle of converting time formats.

Expires

When should a document be considered out of date so that it is no longer cached?

Last-Modified

The last change time of the document. The customer can provide a date through the If-Modified-Since request header, and the request will be treated as a conditional GET, and only documents whose change time is later than the specified time will be returned, otherwise a 304( Not Modified) status will be returned. Last-Modified can also be set using the setDateHeader method.

Location

Indicates where the customer should go to extract the document. Location is usually not set directly, but through the sendRedirect method of HttpServletResponse, which also sets the status code to 302.

Refresh

Indicates how much time, in seconds, the browser should refresh the document. In addition to refreshing the current document, you can also use setHeader (“Refresh”, “5; URL= http://host/path”)”) to let the browser read the specified page.

Note that this functionality is usually achieved by setting the < META HTTP-EQUIV= “Refresh” CONTENT= “5 HTML URL = http://host/path” > in the HEAD area of the HTML page, because automatic refresh or redirection is important for HTML writers who cannot use CGI or Servlet. However, for Servlet, it is more convenient to set the Refresh header directly.

Note that the meaning of Refresh is “refresh this page or visit a specified page after N seconds”, not “refresh this page or visit a specified page every N seconds”. Therefore, a continuous refresh requires that one Refresh header be sent at a time, and sending a 204status code prevents the browser from continuing to refresh, whether using the refresh header or < META HTTP-EQUIV= “Refresh”. >.

Note that the Refresh header is not part of the formal specification of HTTP 1.1, but is an extension, but is supported by both Netscape and IE.

Server

Server name. Servlet generally does not set this value, but is set by the Web server itself.

Set-Cookie

Sets the Cookie associated with the page. Instead of using response.setHeader (“Set-Cookie”,…), Servlet should use the special method addCookie provided by HttpServletResponse. See the following discussion of Cookie settings.

WWW-Authenticate

What type of authorization information should the customer provide in the Authorization header? This header is required in a reply that contains a 401 (Unauthorized) status line. For example, response.setHeader (“WWW-Authenticate”, “BASIC realm=" executives“”).

Note that Servlets generally do not handle this aspect, but instead allow specialized mechanisms on the web server to control access to password protected pages (such as. htaccess).

Powered by TorCMS (https://github.com/bukun/TorCMS).