This is the first day of my participation in the Gwen Challenge in November. Check out the details: the last Gwen Challenge in 2021

What is the HTTP

HTTP Hyper Text Transfer Protocol, translated as Hypertext Transfer Protocol, is the most widely used network Protocol on the Internet.

HTTP protocol is the basis of data exchange on the Web. It is a “client-server” protocol. That is, the request is usually initiated by a recipient such as the browser. A complete Web document is usually a patchwork of different sub-documents, such as text, layout descriptions, images, videos, scripts, and so on.

HTTP was originally designed to provide a way to publish and receive HTML pages.

HTTP request and response messages

Clients and servers interact by exchanging their own messages (as opposed to data flows).

  • Messages sent by clients like browsers are called requests.
  • Messages that are responded to by the server are called responses

HTTP Fundamentals

HTTP was designed as an extensible protocol in the early 1990s. It is an application-layer protocol, sent over TCP, or tlS-encrypted TCP connections, and can theoretically be used by any reliable transport protocol. Because of its scalability, today it is used not only to transfer hypertext documents, but also to transfer pictures, videos, and send information such as HTML forms to the server. HTTP can also update a Web page by retrieving only part of a Web document.

What can HTTP control

The following are common features that can be controlled by HTTP:

  • The cache

  • Open source restricted authentication

  • Basic authentication can be provided directly over HTTP, or HTTP Cookies can be used to set up a specific session.

  • Agent and tunnel

    In most cases, the server and/or client reside on the Intranet, and the real IP address is hidden from the Internet. So HTTP requests have to be brokered across this network barrier.

  • The session

HTTP message structure

The HTTP request message and the response message have a similar structure, consisting of the following parts

  1. Start line: The start line describes the request to be executed, or the corresponding status, success or failure. The starting row is always a single line.
  2. HTTP Headers: An optional collection of HTTP headers that specifies the request or trace message body.
  3. Empty Line: An empty line indicates that all metadata about the request has been sent.
  4. Body: An optional body containing data related to the request, such as HTML form content, or a document related to the response. The size of the body is specified by the HTTP header of the starting line.

The starting line and HTTP headers in the HTTP message are collectively referred to as “request headers,” and the payload is referred to as “message body.”

HTTP request methods

Request header

The request header allows the client to pass additional information to the server. The request header consists of a name (case insensitive) followed by a colon “:” followed by a specific value (without a newline character).

Depending on the context, request headers can be divided into:

  1. Generic header: A header that applies to both request and response messages, but is independent of the data transferred in the final message body.
  2. Request header: A message header that contains more information about the resource to be retrieved or about the client itself.
  3. Entity header: Contains more information about the entity body, such as the content-Length degree of the body or its MIME type.

Response headers

The response header allows the server to pass additional information to the client. The response header consists of a name (case insensitive) followed by a colon (:) followed by a specific value (without a newline character).

Depending on the context, the response header can be divided into:

  1. Generic header: A header that applies to both request and response messages, but is independent of the data transferred in the final message body.
  2. Response header: A message header that contains supplementary information about the response, such as its location or the server itself (name and version, etc.).
  3. Entity header: Contains more information about the entity body, such as the content-Length degree of the body or its MIME type.

The MIME type

MIME types are known as Multipurpose Internet Mail Extensions and are a standardized way to represent the nature and format of a document.

Browsers typically use MIME types, not file extensions, to determine how to process documents; It is therefore important that the server is set up correctly to attach the correct MIME type to the header of the response object.

HTTP / 2.0

HTTP/1.x packets have some performance disadvantages:

  • Headers are not compressed like message bodies.
  • The headers between two messages are usually very similar, but they are still transmitted repeatedly over the connection.
  • Unable to reuse. TCP hot connections are more efficient than cold ones when several connections are open on the same server.

HTTP/2.0 introduces an additional step that splits HTTP/1.x messages into frames and embeds them into streams.