What is an http header?

Table of contents:

What is an http header?
What is an http header?

With the help of http headers, service information is exchanged between the client and the server. This information remains invisible to users, but without it, the browser cannot function properly. For ordinary users, this and the purpose of http headers will seem rather complicated, but in fact they do not contain difficult language. This is what the web user experiences on a daily basis.

http header
http header

What are http headers?

"Hypertext Transfer Protocol" - this is how the http header is translated. Due to its existence, client-server communication is possible. In simple terms, the browser user sends a request, initiating a connection to the server. The latter, by default, waits for a request from the client, processes it, and sends back the final information or response. In the search bar, the user "drives in" the address of the site, which begins with http:// and receives the result in the form of the opened page.

When the website address is printedin the corresponding line, the browser finds the required server using DNS. The server recognizes the http header (one or more) that the client sends to it, and then issues the required header. The required set consists of pre-existing headers and those not found.

In general, http headers are quite effective. They are not visible in the HTML encoding, they are sent before the requested information. Many headers are sent automatically by the server. To send it in PHP, use the header. function

ttp accept header
ttp accept header

Interaction between browser and website

The scheme of interaction between the browser and the site is quite simple. So, the http header starts the query string, which is then sent to the server. In response, the information needed by the client comes. Incidentally, the http protocol has been the most used protocol on the Internet for seventeen years. It is simple, reliable, fast and flexible. The main task of http is to request information from a web server. The client is a browser, and the server is ligthttp, apache, nginx. If the connection between them was successful, the server receives the necessary information in response to the request. http information contains text, sound files, videos.

Protocol can be a transport for others. The client request consists of three parts:

  • start string (message type);
  • headers (message parameters);
  • body of information (a message separated by a blank line).

Starting string is a required element of the http header field request. Request StructureThe user interface consists of three main parts:

  1. Method. It specifies the type of request.
  2. Path (path). This is the URL string that follows the domain.
  3. Protocol used. It consists of protocol version and

Modern browsers use version 1.1. Headings follow in the format "Name: value".

caching http headers on nginx server
caching http headers on nginx server

HTTP caching

The bottom line is that caching provides storage of HTML pages and other files in the cache (a place in the operating memory, on the computer's hard drive). This is necessary in order to speed up re-access to them and save traffic.

The cache has a client browser, an intermediate gateway, and a proxy server. Before sending a message to the URL, the browser will check if the object is in the cache. If the object is not present, the request is passed to the next server, where the caching of http headers on the nginx server is checked. Gateways and proxies are used by different users, so the cache is shared.

HTTP caching can not only significantly speed up the site, but also provide an old version of the page. Site caching sends headers to the response. However, information requested via the HTTPS protocol cannot be cached.

http header fields
http header fields

Description of http headers

One of the most important cache mechanisms is http headers expires. These headers report the expiration date of the information provided in the response. They indicate the time and datewhen the cache is considered stale. For example, such a header looks like this: Expires: Wen, 30 Nov 2016 13:45:00 GMT. This structure is used almost everywhere, including for caching pages and pictures. If the user selects an older date, the information will not be cached.

Http proxy headers belong to the header link category. They are not cached by default. For the cache to work properly, each URL must match one content variant. If the page is bilingual, each version must have its own URL. The vary header tells the cache the names of the request headers. For example, if the rendering of a request is browser dependent, the server needs to send a header as well. Thus, different variants of requests and types of documents are stored in the cache. The accept TTP header is needed to list the acceptable formats of the resource being used, it's fairly easy to work with as it filters out the unnecessary ones.

There are four groups of headers in total that convey service information. These are the main headers - they are contained in any server and client message, request and response, and entity. The latter describe the content of any message from the client and server.

HTTP authorization header is considered optional. When a web page asks the client for authorization, the browser displays a special window with fields for entering a username and password. After the user enters their data, the browser sends an http request. It contains the "authorization" header.

http headersproxy
http headersproxy

How can I see the headlines?

To see the http header, you need to install browser plugins, for example, firefox:

  • Firebug. You can view the headers in the net tab (network), where select all (all). This plugin has features that will be useful for a web developer.
  • Live http headers. A simple plugin for viewing http headers. With it, you can manually generate a request.
  • Grome users can easily see the titles if they click the settings button, select developer tools (net works).

When the plugins are installed, launch them and refresh your browser page.

Request Methods

The methods that are used in HTTP are similar to the instructions that are sent as a message to the server. This is a special word in English.

  • GET method. It is used to request information from a resource. It is from him that all actions begin.
  • POST. It is used to send data. For example, a message on a social network or a comment, the browser puts it in the body of the POST request and sends it to the server.
  • HEAD. The method has similarities to the first one, but performs an easy function. It only asks for metadata, excluding the message from the response. The method is used if they want to get information about files without downloading. It is used if they want to check the functionality of links on the server.
  • PUT. Loads data into a URL. Transfers large amounts of data.
  • OPTIONS. Works with server configurations.
  • URI. Identifies the resource and contains the URL.
protocol http header
protocol http header

Structure of http response

The server responds to client requests with long messages. The response consists of several lines, which indicate the version of the protocol, the server status code (200). It says what has changed on the server during the processing of the incoming request:

  1. Status "two hundred" indicates successful processing of information. The server then sends the document to the client. The remaining lines of the request indicate other information about the transmitted information.
  2. If the file is not found or does not exist, the server sends a 404 code to the client, also called an error.
  3. Code 206 indicates a partial file download that can be resumed after a while.
  4. Code 401 indicates authorization denied. This means that the requested page is protected by a password, which must be entered to confirm the login.
  5. Access denied, code 403 says. Denies to view, download files or videos is a common response on the Internet.
  6. There are also other versions of the codes: temporary relocation of the requested file, internal server error, permanent relocation. In this case, the user will be redirected. If the code 500 appears, it means that there are server failures.

URL - what is it?

URL is the heart of web communication between client and server. The request is usually sent via a URL - Uniform Resource Locator. The url request structure is very simple. It consists of severalelements: http protocol (header), hoot (site address), port, resource path and query.

Protocol is also available for secure https connection and information exchange. The URL contains information about the location of a particular site on the Internet. The address includes the domain name, the path to the page, as well as its title.

The main disadvantage of working with URLs is the inconvenient interaction with the Latin alphabet, as well as numbers and symbols. In SEO optimization, the url plays an important role.

http headers expires
http headers expires

Helpful tips

Heavy computer users and developers would be reluctant to read some of the professional advice given by experts in this field:

  • Indicate the expiration dates of files and documents, taking into account updates. Statistical information is indicated in large max-age values.
  • A single document must be accessible from only one URL.
  • If you are updating a file that will be downloaded by the user, change its name and link to it. This ensures that a new document is downloaded and not an outdated document.
  • Last-Modified headings must match the actual date the content was last modified. You should not save pages and documents unless you change them.
  • Use POST requests only where necessary. Minimize your SSL work.
  • Headers should be checked by the REDbot plugin before being sent by the server.

Popular topic

Editor's choice