preface
Hello everyone, I am zaa 👦, a little bit of effort every day 💪, can be promoted and raise 💰 become general manager as CEO marry Bai Fumei on the peak of 🗻, think there is a little excitement 😎.
✍, this is the content of my 12th article, hope to be able to explain every knowledge point, (of course, if which do not know, can discuss in the comments section oh!). ⏰, time begins!
If you find this article helpful, please like, bookmark, comment, leave your footprints of learning 👣, I’d love to talk about 😃
Learning to read this article requires a bit of front-end networking, at least if you’ve used the interface and understood the backend. (Also know a little network knowledge, but not how to understand the learners)
It’s important to learn the Http protocol, to understand the interaction between the front and back ends of a Web application, and so on
HTTP
What is HTTP, HTTPS, HTTP2, DNS, TCP, CDN and so on in the network, you are not confused? Do you have a lot of question marks? 😧
The Web is built over the HTTP protocol
So let’s start with the HTTP protocol, the HTTP protocol:
Features: 1. Simple and fast, 2. Flexible, 3. Connectionless, 4. (Remember that)
HTTP packet: request packet and response packet
Request message:
- Request line: request method, request URL, HTTP protocol and version;
- Request header that notifies the server that it has information about the client request
- Blank lines, send carriage returns and newlines
Response message:
- The status line
- Response headers
- A blank line
- Response body
Methods the HTTP:
The main GET method gets data, and the POST method transfers resources
The PUT method updates the resource, the DELETE method deletes the resource, and the HEAD method obtains the packet header
Of course, as programmers often use HTTP status code:
I think most of you are familiar with this part of the comparison, right? So I’m going to add something.
Let’s take a look at the basics of the Web web. We know that we access the Web using the HTTP protocol, but do you know what happens when we enter a URL in the address bar of a web browser?
The first step is 👣. The browser submits the requested URL to the DNS for domain name resolution, finds the real Ip address, and sends a request to the server.
The second step 👣, the server to the background processing, return the response data, the browser to receive the file.
The third step is 👣. The browser parses the loaded resources (according to the URL specified in the address bar of the Web browser, the web browser obtains information such as file resources from the Web server) and establishes the corresponding internal data structure.
In the fourth step 👣, the browser loads the parsed resource file and renders the web page.
So, even if you don’t know how it works, you can see the Web page.
The client obtains the resource from the server through the specified access address. The server communicates with the client through HTTP and passes the resource to the client.
After you enter the URL in the browser address bar, the message is sent somewhere, and the response from somewhere is displayed on the Web page.
So, THE HTTP protocol is hypertext transfer Protocol, which is used to transfer hypertext from the World Wide Web server to the local browser.
HTTP is used to transmit data based on THE TCP/IP communication protocol. It is mainly a communication format between the client and the server, and does not involve data packet transmission.
So what is the network infrastructure TCP/IP
Network basic TCP/IP
Of course, when it comes to the basic network TCP/IP, it is necessary to understand the TCP/IP protocol family!
Commonly used networks operate on the basis of the network base TCP/IP family of protocols, so, plus, as mentioned earlier, HTTP is a subset of it. Mathematical concepts)
Protocol is the definition of rules. Both parties need to define the rules in advance before they can communicate with each other. The basic network TCP/IP is the general name of all kinds of protocol families related to the Internet.
In the HTTP diagram, the TCP/IP protocol family is divided into four layers: the application layer, the transport layer, the network layer, and the data link layer (layered).
Using TCP/IP protocol family for network communication:
The sender (client) moves down from the application layer, and the receiver (server) moves up from the link layer.
That is, the client, application layer (HTTP client) can do it “in case of trial, transport layer (TCP) can do it, network layer (IP) can do it, Link layer (network) can do it; Server, application layer (HTTP server), ⬅ Transport layer (TCP), ⬅ network layer (IP), ⬅ link layer (network).
From the sender to the receiver, the process of sending AN HTTP request is as follows:
The sender adds a header every time it passes through a layer, and the receiver deletes a header every time it passes through a layer. The sender initiates an HTTP request from the sender: The application layer, HTTP data (HTTP packets), accepts THE TCP header to the transmission layer, i.e., THE TCP header contains HTTP data, accepts IP packets to the network layer, i.e., the FIRST IP strand contains the TCP header and the TCP header contains HTTP data, and accepts the network architecture to the link layer, i.e., the Ethernet header contains the IP header, The IP header contains the TCP header, which contains HTTP data. This is the transmission at the sending end.
Then the link layer of the sender will transmit to the link layer of the receiver, that is, the HTTP data transmitted through each layer will be deleted, so, (Ethernet header 👉IP header 👉TCP header 👉HTTP data), from the sender to the receiver, and the receiver will go up each layer to delete the header (link layer to the application layer), so, After the link layer of the receiver deletes the header (P header 👉TCP header 👉HTTP data) from the network layer, the HTTP data is left at the application layer of the receiver.
So someone said, what about the seven layer protocol in the computer network? Yes, there are seven layers, but none of them will affect it, so just to talk about the seven-layer protocol, by the way.
On the host: application layer, presentation layer, session layer, transport layer; On the network: network layer, link layer, physical layer.
The above can be part of a part of the knowledge point to learn to master.
The difference between GET and POST in HTTP
While surfing the Web, I came across the article “99% of people GET the difference between GET and POST in HTTP wrong.”
A major difference between GET and POST is that GET generates a TCP packet; POST generates two TCP packets.
For a GET request, the browser sends the HTTP header and the data, and the server responds with 200. For a POST request, the browser sends the header, the server responds with 100 continue, the browser sends the data, and the server responds with 200.
Then read the article “Heard that 99% of people GET the difference between GET and POST in HTTP wrong”?? XMLHttpRequest (XHR) Uses Multiple Packets for HTTP POST? Can oneself check! (Put forward their own thinking, constantly ask why, to expand their knowledge edge)
How many HTTP requests can a TCP connection send
So, how many HTTP messages can be sent from a TCP connection? 😉, should be TCP connection continuously open, can always send a request, continuously open can casually send, HTTP2 words can be a connection in parallel, HTTP/1.1 can not. (Pipelining can be used in http1.1, but Pipelining is not enabled in browsers by default)
(The feeling should be related to the network condition, there is no such thing as one is faster than the other)
Does a TCP connection disconnect after an HTTP request completes?
In HTTP/1.0, a server breaks the TCP connection after sending an HTTP response. However, this request will re-establish the TCP connection with the port, which is too costly.
If a server supports the Connection: keep-alive Header. After completing the HTTP request, do not disconnect the HTTP request using TCP TCP connection, can be reused, after sending the HTTP request does not need to re-establish the TCP connection.
By default, TCP connections are not broken. Only if you declare Connection: close in the request header will the Connection be closed after the request is completed.
A TCP connection can send multiple HTTP requests if the connection is maintained.
Can HTTP requests sent in a TCP connection be sent together?
In PiPelining to solve this problem :(what is PiPelining?)
As shown in figure:
With that out of the way, let’s take a look at IP,TCP, and DNS(briefly, but possibly more)
IP, TCP, and DNS
When it comes to IP, TCP, DNS, of course, in network communication, the hierarchy is involved so I’ll talk about it or I’ll forget about it.
TCP/IP is a class of protocol systems, it is a set of protocols for network communication
TCP header format
The first format
Responsible for the transmission of IP protocol, IP protocol in network layer), almost all of the system using the network to the IP protocol, TCP/IP protocol is used for various data packets sent to each other, need to make sure that two important conditions, the IP address (that nodes are assigned to address, IP) may be substituted and MAC address (refers to the network card belonging to a fixed address, MAC addresses are basically unchanged).
MAC address ARP is used for communication. (ARP is a protocol for resolving addresses. You can check the CORRESPONDING MAC address based on the IP address of the communicator.) The ARP protocol is used to search for the next forwarding address when a communication party reaches the other party through multiple computers and network devices. (If the express company, you, as the person who sent the express, only know that your express has been sent to the express company, during the express process, you cannot understand the details of the express process)
That is to say, the sending end yearning for a certain IP address to send packets (express packets) through ARP protocol to transfer the packets to a MAC address (router) a transfer station, and then to the next transfer address (by the previous transfer address search (send) to the next transfer address), and finally to the receiving end.
Packets:
I know that THE MAC address communication process is using ARP protocol, but this is used in the communication rarely on the same LAN situation.
TCP is used to ensure reliability. It is located at the transport layer and provides the byte stream service
The byte stream service is used to split large chunks of data into packets in the unit of segment for management (mainly for convenient transmission).
And to make sure that the data is delivered reliably, this is what we call the TCP protocol using a three-way handshake to make sure that the data is delivered correctly. (TCP establishes connection – three-way handshake, TCP releases connection – four-way wave (more on that later))
Three handshakes, four waves
The TCP flag, SYN (Synchronize) signal, and ACK (acknowledgement) signal are used during the handshake.
The description is :(three handshakes)
First handshake: The sender sends the packet marked SYN to the receiver and waits for the receiver to receive the packet.
Second handshake: After receiving the packet, the receiver sends a PACKET marked SYN/ACK to convey the acknowledgement.
Third handshake: After receiving the packet, the sender returns the packet with ACK identifier to the receiver and receives the packet by handshake.
The sender sends the packet marked SYN to the receiver. The receiver sends the packet marked SYN/ACK to the sender, and the sender sends the packet marked ACK to the receiver.
The SYN and ACK are the control bits in TCP packets.
Describe the process: four waves
Usually, we are used to memorizing domain names, but the machines recognize each other’s IP addresses. The translation between them is called domain name resolution, and the domain name resolution needs to be completed by a special domain name resolution server.
So, the DNS service is responsible for domain name resolution.
DNS service is responsible for domain name resolution
The DNS service that resolves domain names is used to query specific IP addresses based on domain names.
When the client makes a query request, it looks up the query information in the cache on the local computer. If the query information cannot be obtained locally, it sends the query request to the DNS server.
, the client will request sent to the local DNS server domain name query, on the server management is recorded in the area of the search, if found the record, the use of the record for parsing, if there is no area information can meet the requirements of the query, cannot find the client queries on the local information, sends a request to the root domain DNS server, The root domain part that resolves client requests, returns the DNS server address containing the next-level domain name information to the DNS server address of the client, and finally finds the corresponding IP address information on the DNS server of the target domain name.
The DNS service is a protocol at the application layer that resolves domain names and IP addresses. (The DNS service is easier to understand with the addition of domain name purchasing and resolution services, which are computers that use host names or domain names instead of IP addresses.) It provides the ability to look up IP addresses by domain names or reversely look up domain names from IP addresses.
In detail, the sender sends a request to the DNS to inform me of the IP address under a certain domain name. After receiving the request, the DNS returns the corresponding IP address to the sender. The sender can send access requests to the Web server using the IP address.
So, based on the above summary, I can describe the communication process of HTTP protocol:
HTTP communication process
A client (browser) accesses a web page with a domain name in the address bar and sends a request to the DNS server for the corresponding IP address. The browser uses the domain name to request the web page resources under this domain name. The HTTP protocol generates HTTP request packets for the target Web server. TCP divides HTTP request packets into segments and reliably sends them to the peer. Through (packet transfer station) IP protocol responsible for the place, the search for the other side of a MAC address router, while the transfer side. After receiving the packet from the peer server (an Ip address), TCP receives the received packet segments from the peer server. After regrouping the packet segments, HTTP processes the contents requested by the Web server in the original order.
This process is the transfer between the application layer, transport layer, network layer and link layer.
What is the request packet that the client sends an HTTP request to the server?
As mentioned above, the request packet is as follows:
This is a request packet from the client, so there is also a response packet from the server. It is the received result and returns in the form of response packet:
Use a table to describe the use of GET to obtain resources:
instructions | describe |
---|---|
request | GET/index. HTTP / 1.1 HTML |
The response | returnindex.html Page resources |
So, HTTP packet is used for THE information of HTTP protocol interaction. A packet is a string of text composed of multiple lines of data. Packet header and packet body are roughly divided into two parts.
Message structure
The structure of the request and response messages (find the following picture to explain)
Of course, if it’s not clear enough, find a few more pictures:
Request header
Request body
The status line
In response to the head
Response body
The Uniform Resource Locator is the Uniform Resource Locator. The Uniform Resource Locator is the Uniform Resource Locator. A URL is the address of a web page that you enter in the address bar.
URI
Speaking of URLS, we need to look at URIs, which are the same resource identifier. Learn about the absolute URI format.
Uris are used to locate resources on the Internet and ensure that resources can be accessed anywhere on the Internet (HTTP protocol uses URIs to enable clients to locate resources). The diagram below:
So if you look at this quickly you should know a lot about HTTP.
What’s the difference between GET and POST?
Here’s a common interview question: What’s the difference between GET and POST?
- GET will not be requested again in the browser rollback, and POST will submit the request again
- GET requests are cached by the browser. POST requests are not cached by the browser
- GET request parameters are fully preserved in the browser history; POST parameters are not
- GET requests have a length limit on the parameters they pass in the URL, while POST has no limit
- The GET parameter is passed through the URL and the POST is placed in the Request body
Four versions of HTTP
They are HTTP1.0, HTTP1.1, HTTP/2, and HTTP/3
HTTP1.0 is a short connection by default. Each time you interact with the server, you need to open a new connection.
In the HTTP1.1 version, the default persistent connection is maintained as long as the port is not explicitly stated, the HTTP request can be sent multiple times, and the emphasis is on breakpoint continuation, using the HTTP header to block the body of the entity using the block transfer encoding.
The HTTPS protocol is now used by some websites.
On the network, the client and the server interaction, it may be hijacked, need to use CA (public trust agency) to help the client to identify the server is real.
In this case, you need to apply for a digital certificate. The digital certificate contains information about the certificate holder, certificate validity period, and server public key.
The client uses the CA’s public key to decrypt the certificate (the certificate is decrypted by the CA’s private key, and then the client uses the CA’s public key to decrypt the certificate).
The process is shown in the figure below:
Pipelined and durable connections
Pipelinization is only supported in HTTP/1.1, where requests are sent in a single packet and responses are sent back in a single packet with a persistent connection.
Pipelining technology allows you to send the next request without waiting for a response.
By default, all links in HTTP1.1 are persistent, using the same TCP connection to send and receive multiple HTTP requests or responses.
HTTP Persistent Connections, also known as HTTP keep-alive or HTTP Connection reuse
Benefits:
- It reduces the extra overhead caused by repeated establishment and disconnection of TCP connections
- Reduces the load on the server
- Web pages display faster
Cookie
Cookie technology controls the state of the client by writing Cookie information in the request and response packets
Cross domain
What is the same origin policy
The same-origin policy is a convention. It is the core security function of browsers. Same-origin means that the protocol, domain name, and port are the same.
Cross-domain means that the request can be sent, the server can receive the request and return the result normally, but the result is intercepted by the browser.
Solve cross-domain:
There are jSONP, iframe, CORS, IMG, HTML5 postMessage, and more. The principle of using HTML tags to cross domains is that HTML is not affected by the same origin policy. But it’s just a Get request, just to be clear.
JSONP principle, the use of JS request return does not need a domain name, no cross-domain problems, that is, the use of
JSONP is simple to use and compatible, but it is limited to GET requests.
<script src="http:=jsonp"></script>
<script>
function jsonp(data) {
console.log(data)
}
</script>
Copy the code
What happens between entering the URL and displaying the page?
Show the complete flow diagram from the input URL to the page
Enter the URL and press enter, the browser process checks the URL, assemitates the protocol, forms the complete URL, sends the URL request to the network process through the inter-process communication (IPC), after receiving the URL request, checks whether the local cache cache the requested resource, if so, returns the resource to the browser process, if not, The network process sends an HTTP request to the Web server.
Make an HTTP request to the Web server
- Perform DNS resolution to obtain the IP address and port of the server
- Establish a TCP connection with the server using the IP address
- Build the request header
- Send the request header
- After the server responds, the network process receives the response header and the response information and parses the response content
- The network process resolves the response process
- Prepare the render process
- Transfer data and update status
The Web server
- Using a single virtual host to achieve multiple domain names
- The HTTP/1.1 specification allows one HTTP server to host multiple Web sites
Proxy, gateway, tunnel
Agent:
Gateway:
Tunnel:
Cache:
Expiration date:
Web security
- The plaintext communication may be wiretapped, and the communication content may be wiretapped
- TCP/IP Networks that may be eavesdropped on
- Encrypted processing to prevent eavesdropping
- Packet integrity cannot be proved and may have been tampered with
- Using HTTPS to communicate
- HTTP+ encryption + authentication + integrity protection =HTTPS
reference
Guess how many HTTP requests can be sent over a TCP connection
Front end summary – Network
Stayed up all night writing an HTTP summary
Illustrated HTTP