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?

  • What an interesting question you have about how to understand which one to send . I think that you need to continue to read about http-requests. Of course, Google’s Google Search button is an input with the type of submit , but you haven’t yet finished reading such interesting depths :) - Denis Bubnov
  • Hm but I do not understand your question. it is not clear what can be difficult for the browser to understand. seeing the address www.google.com http request will be GET / Host: www.google.com well, and even standard headers with the date, information about the browser, etc. - Mike
  • @Mike, you should probably close such a question? - Denis Bubnov
  • @DenisBubnov Xs. I prefer not to rush, suddenly the author of the question specifies it - Mike
  • @DenisBubnov, that is not, I did not mean when we type google.com into the input field, but when it’s stupid to type www.google.com in the browser ... well, it's clear that it returns something that keeps -alive ... but this is only one answer ... how is the interaction going on? At what point do we get the html page itself? - xperious

1 answer 1

The browser does not understand which request to send, but forms it.

The browser places the following information in the request body:

  1. The type and version of the protocol used is usually HTTP/1.1 .
  2. Type of request - GET to follow links, plus PUT and POST for forms.
  3. Site name - several sites can be located (hosted) on one IP address, and therefore the browser always places this information.
  4. 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 Host field.
  5. Supported features - compression algorithms, system language, HTTP2 support , and so on.
  6. The information previously transmitted by the server is cookies, ETag and 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.

  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin