"Go" http Learning---diagram http[three-time handshake &&iso Model]

Source: Internet
Author: User
Tags ack

"Turn" https://www.toutiao.com/i6592556686068679182/

Start by understanding the steps required for a complete HTTP request-to-response process:

1. Domain Name resolution

2.3-time handshake to initiate TCP

3. Initiating an HTTP request after establishing a TCP connection

4. Server-side response HTTP request, the browser gets HTML code

5. The browser parses the HTML code and requests the resources in the HTML code

6. The browser renders the page rendering to the user

1. Domain Name resolution

is to turn the website name into an IP address: localhost-->127.0.0.1

Like what hosts file, DNS domain name resolution and so on can realize this function

2.3-time handshake to initiate TCP

When a normal TCP network connection is established between the client and the server:

The client sends a SYN message first,

The server uses the Syn+ack answer to indicate that the message was received.

Finally, the client responds with an ACK message.

This allows a reliable TCP connection to be established between the client and the server, and the data can be passed between the client and the server.

What is the process of a complete HTTP transaction?

After receiving the IP address of the domain name, user-agent (typically the browser) initiates a TCP connection request to the server's Web program (usually Httpd,nginx, etc.) with a random port (< port < 65535). This connection request (the original HTTP request passes through the layer layer of the TCP/IP4 layer model) arrives at the server side (this intermediate through various routing devices, except inside the LAN), enters to the network card, then enters into the kernel TCP/IP protocol stack (used to identify the connection request, unpack the packet, a layer of peel off), It is also possible to pass the filtering of the NetFilter firewall (which is the kernel module) and finally arrive at the Web program (Nginx for example) and finally establish a TCP/IP connection.

3. Initiating HTTP requests (HTTP request)

The so-called HTTP request, which is the Web client sending information to the Web server, consists of three parts:

(1) Request Line

Example: GET www.cnblogs.com http/1.1

The request line notation is fixed and consists of three parts,

The first part is the request method:

In addition to the common only get and post methods, there are actually many HTTP request methods, such as: Put method, Delete method, head method, connect method, trace method

The second part is the request URL,

The third part is the HTTP version.

(2) HTTP header

HTTP headers can be 3 HTTP headers in an HTTP request: 1. Request Header 2. Normal header (general header) 3. Solid Head (Entity header)

Generally, because get requests often do not contain content entities, there is no entity header.

(3) content

Only exists in the POST request because the GET request does not contain any entities

4. Server-Side HTTP response (HTTP Response) Request

When the Web server receives an HTTP request, it does some processing based on the requested information (the processing may be simply a static return page, or it will be returned after processing by a language such as ASP. NET, PHP, JSP, etc.), returning an HTTP response accordingly. HTTP responses are structurally similar to HTTP requests and are made up of three parts, namely:

1. Status line

Example: http/1.1 OK

The first part is the HTTP version

The second part is the response status code

The third part is the description of the status code

Information Classes (100-199)

Response Successful (200-299)

Redirect Class (300-399)

Client Error Class (400-499)

Service-Side Error Class (500-599)

2.HTTP Head

The headers included in the HTTP response are: 1. Response Header (response header) 2. Normal header (general header) 3. Solid header (Entity headers).

3. Return content

The HTTP response content is the information requested by the HTTP request. This information can be either an HTML or a picture. The data format of the response is obtained through the Content-type field: content-type:image/png; or the content-type:text/html we're familiar with.

The following are the values of some common content-type fields.

Text/plain

Text/html

Text/css

Image/jpeg

Image/png

Image/svg+xml

Audio/mp4

Video/mp4

Application/javascript

Application/pdf

Application/zip

Application/atom+xml

5. The browser parses the HTML code and requests the resources in the HTML code

Sometimes we get an HTML page, in the process of parsing the browser to HTML, if we find that the additional URL needs to get the content, it will launch the HTTP request again to get the server, such as style files, pictures. Many HTTP requests, relying on only one TCP connection, are sufficient, which is called persistent connections. It is also called an HTTP request complete.

"Go" http Learning---diagram http[three-time handshake &&iso Model]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.