hello, I understand the http protocol ... about headers, requests, answers read ... but the basic question is not clear: there is just http address, say, www.google.com, and so it’s interesting how the browser understands which http request Need to send to get an answer?
1 answer
The browser does not understand which request to send, but forms it.
The browser places the following information in the request body:
- The type and version of the protocol used is usually
HTTP/1.1. - Type of request -
GETto follow links, plusPUTandPOSTfor forms. - Site name - several sites can be located (hosted) on one IP address, and therefore the browser always places this information.
- The path to the requested page (or file or other resource) relative to the root of the site - when the grass was green, the sky was blue, and each site was allocated a separate white address, the site name was optional and was made in the
Hostfield. - Supported features - compression algorithms, system language, HTTP2 support , and so on.
- The information previously transmitted by the server is cookies,
ETagand so on.
The recipient of the request is received by the browser using DNS. With its help, he finds out what IP address corresponds to the name of the site.
There, roughly speaking, a state machine is implemented, which, depending on the response, sends a different request or how?
There is no state machine in HTTP (this is a stateless protocol). The browser makes a request, receives a response and terminates the connection, after which the server completely forgets about us and our request. Even when using keep-alive optimization, the server works with a packet of requests completely independently.
Therefore, the cookie mechanism was invented so that the client could somehow remind himself of the server to himself, sending him in the request body all the cookies obtained from the earlier answers of this site.
The following request will be made only at the request of the user, when you click the link or form submit button.
And so, it is required to re-send the same headers, duplicating them from the request to the request. By the way, HTTP2 was invented to solve this problem, but this is a completely different protocol.
submit, but you haven’t yet finished reading such interesting depths :) - Denis Bubnov