Using the http headers, service information is exchanged between the client and server. This information remains invisible to users, but without it the correct operation of the browser is impossible. For ordinary users, the information about this and the tasks of http headers will seem rather complicated, but in fact they do not contain difficult formulations. This is what the web user encounters daily.
What are http headers?
“Hypertext Transfer Protocol” - this is how the http header is translated. Due to its existence, a client-server connection is possible. To explain in simple words, 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 a page that opens.
When the site address is printed in 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 already existing headings and not found.
In general, http headers are quite effective. They are not visible in the HTML coding, they are sent before the requested information. Many headers are automatically sent by the server. In order to send it in PHP, you should use the header function.
Browser-site interaction
The interaction between the browser and the site is quite simple. So, the http header begins the request line, which is then sent to the server. In response, the information necessary for the client comes. By the way, the http protocol is already seventeen years old - the most used on the Internet. It is simple, reliable, fast and flexible. The main task of http is to request information from a web server. The client is the browser, and the server is ligthttp, apache, nginx. If the connection between them is successful, the server receives the necessary information in response to the request. The http information contains text, sound files, videos.
A protocol may be a vehicle for others. The customer request consists of three parts:
- start line (message type);
- headers (message parameters);
- body of information (message that is separated by an empty line).
The start line is a required element of the request for the http header field. The structure of the user request consists of three main parts:
- Method. With its help, the type of request is indicated.
- Path This is the URL string that follows the domain.
- Protocol used. It consists of protocol and http versions.
Modern browsers use version 1.1. The following are headings in the format "Name: Value".
HTTP caching
The bottom line is that caching provides storage of HTML-pages, 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 by URL, the browser will check the presence of the object in the cache. If there is no object, the request is sent 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. Using site caching , headers are sent to the response. At the same time, the information requested by the HTTPS protocol cannot be cached.
Description of http headers
One of the most important cache mechanisms are http expires headers. These headers report the expiration date of the information provided in the response. They indicate the time and date when the cache will be considered obsolete. For example, such a title 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 the old date, the information will not be cached.
The http proxy headers are in the header link category. They are not cached by default. For the cache to work correctly, each URL must correspond to one variant of the content. If the page operates in two languages, each version must have its own URL. The vary header tells the cache the names of the request headers. For example, if the display of the request depends on the browser, the server must also send a header. Thus, the cache stores different query options and document types. The accept TTP header is necessary in order to compile lists of acceptable formats of the resource used, it is quite easy to work with it, since it eliminates unnecessary ones.
There are four groups of headers that transmit overhead information. These are the main headers - they are contained in any message from the server and client, the request and response, as well as the entity. The latter describes the content of any message from the client and server.
The HTTP authorization header is considered optional. When the web page asks the client for authorization, the browser displays a special window with fields for entering the login and password. After the user enters his data, the browser sends an http request. It contains the heading "authorization".
How to 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, where you can select all. This plugin has features that will be useful to the web developer.
- Live http headers. A simple plugin designed to view http headers. Using it, you can manually generate a request.
- Ghrome users will easily see the headers if they click on the settings button and select the developer tools (net works).
When the plugins are installed, launch them and refresh your browser page .
Request Methods
The methods 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 with him that all actions begin.
- POST With its help, data is sent. For example, a message on a social network or a comment, the browser places in the body of the POST request and sends it to the server.
- HEAD The method has similarities with the first, but performs an easy function. It requests only meta data, excluding the message from the response. Use the method if you 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 to a URL. Transmits large amounts of data.
- OPTIONS. Works with server configurations.
- URI Identifies a resource and contains a URL.
Response http structure
The server responds to client requests with long messages. The answer consists of several lines, which indicate the protocol version, server status code (200). He talks about what has changed on the server during the processing of an incoming request:
- The status of "two hundred" indicates the successful processing of information. After that, the server sends the document to the client. The remaining lines of the query indicate other information about the transmitted information.
- If the file is not found or does not exist, the server sends the client code 404, it is also called an error.
- Code 206 indicates a partial download of the file, which can be resumed after a while.
- Code 401 indicates a denial of authorization. This means that the requested page is protected by a password that must be entered to confirm the entry.
- Forbidden access, says code 403. Bans on viewing, downloading files or videos is a common answer on the Internet.
- There are also other versions of codes: temporary movement of the requested file, internal server error, final movement. In this case, the user will be redirected. If the code 500 appears, it means that the server has crashed.
URL - what is it?
URL is the heart of web communication between client and server. A request is usually sent via a URL - a single resource index. The url request structure is very simple. It consists of several elements: http protocol (header), hoot (site address), port, resourte path and query.
The protocol is also available for secure https connection and exchange of information. 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 name.
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 address plays an important role.
Useful Tips
Active computer users and developers should not get acquainted with some professional recommendations that experts in this field give:
- Designate the expiration dates of files and documents, taking into account updates. Statistical information is indicated in large max-age values.
- A single document should be accessible at only one URL.
- If you update the file that will be downloaded by the user, change its name and link to it. This ensures that a new, not obsolete, document is downloaded.
- Last-Modified headers must be up to date with the latest content changes. Do not re-save pages and documents unless you change them.
- Use POST requests only where needed. Minimize SSL.
- Headers before sending the server should be checked by the REDbot plugin.