Links to study materials

HTTP interview article

1. What parameters are in the HTTP request header and response header

Request Headers

  • Accept: Indicates the type of resources that can be received by the client
  • Accept-language: indicates the language type that the client can receive
  • Accept-encoding: Indicates the type of compressed data that can be received by the client
  • Connection: indicates the connection between a client and a server
  • Host: destination Host and port number (for virtual hosts)
  • User-agent: indicates the client version number
  • Cookie: the client temporarily stores information about the server
  • Date: indicates the time when the client requests the server

Response Headers

  • Connection: indicates the Connection between a client and a server
  • Content-encoding: Server compression Encoding type
  • Content-type: resource Type application/json; charset=utf-8 ; text/css; application/javascript;
  • Content-length: indicates the Length of compressed data
  • Cache-Control
  • Last-modified: indicates the Last modification time
  • Etag: last modified time
  • Access-Control-Allow-Credentials
  • Access-Control-Allow-Origin
  • Access-Control-Allow-Methids
  • Date: indicates the response time of the server

2. The cookie options

Read cookies

  • Name
  • Value
  • Domin
  • Path
  • Expires/MaxAge
  • Size
  • HttpOnly: disables JS from reading cookies
  • Secure: Only HTTPS can carry cookie information
  • SameSite: Disables cross-domain and prevents
  • Priority: Priority

3. What is HTTP and the difference between HTTPS and HTTP

The HTTP protocol

Hypertext transfer protocol (HYPERtext Transfer Protocol) is a standard for network communication

  • Flexible: Supports client/server mode
  • Simple and fast: When a client requests a server, it only needs to send the request method and path
  • Connectionless: Only one request is processed per connection and then the connection is disconnected
  • Stateless: The HTTP request cannot be processed based on the previous status

The HTTPS protocol

HTTP is insecure because it transmits data in plain text. Therefore, HTTPS = HTTP + SSL/TLS allows HTTP to run on secure SSL/TLS. The SSL certificate is used to verify the identity of the server and encrypt the communication between the browser and server

SSL/TLS runs between TCP/IP and application-layer protocols. When setting up SSL connections between the browser and server, you need to select a set of encryption algorithms to secure data communication

The difference between

  • HTTP is not secure for plaintext transmission
  • The default port is 80 for HTTP and 443 for HTTPS
  • HTTPS requires an SSL certificate, which is expensive and expensive

4. How to ensure HTTPS security

Problems with HTTP

  • Using plaintext communication, content can be eavesdropped
  • Does not authenticate and may therefore be disguised

HTTPS

The HTTP protocol runs on SSL/TSL, and the security is guaranteed by SST

SSL: Secure Socket Layer TSL: Transport Layer protocol

advantage

Information encryption, integrity verification, authentication

implementation

The implementation of SSL relies mainly on the following means

  • Symmetric encryption: Encrypts data with negotiated keys
  • Asymmetric encryption: Implements identity authentication and key negotiation
  • Algorithm: verify the integrity of information
  • Digital signature: authentication

Symmetric encryption

The encryption and decryption keys are the same. As long as the symmetric key is secure, the communication security can be guaranteed, and how to ensure that the other party gets the secure symmetric key is to use asymmetric encryption technology.

Asymmetric encryption

Public key encryption and private key decryption, public key can be used by anyone, the private key is confidential

Mixed encryption

In HTTPS communication, symmetric encryption and asymmetric encryption are used.

The party that sends the ciphertext uses the other party’s public key to encrypt the symmetric key. In this way, the other party uses its private key to obtain the symmetric key, and then uses the symmetric key to encrypt communication

The algorithm

A particularly popular compression algorithm, commonly known as the hash function, generates a digital fingerprint for the data. When you send a piece of data, you send her summary, and the other person receives the data and compares it to see if the data has been modified.

A digital signature

A digital signature determines that a message was sent with the sender’s signature, which cannot be faked.

The principle is to use private key encryption, public key decryption.

A signature is as public as a public key.

CA verification body

Introduce a third party to ensure security

5. How to understand UDP and TCP, the differences, and application scenarios

TCP

Transmission control protocol.

UDP

User packet protocol, simple packet oriented communication protocol, that is, the application layer handed down the report, do not merge, do not split, just above the head was handed over to the following network layer.

The difference between

  • Reliability: TCP is reliable (connection-oriented and not lost), UDP is not reliable (connection-oriented and may be lost).
  • Connectivity: TCP connection-oriented, UDP connectionless
  • Packet: TCP byte stream oriented, UDP packet oriented
  • Dual properties: TCP full-duplex, UDP one-to-one, one-to-many, and many-to-many
  • Flow control: TCP sliding window, UDP None
  • Congestion control: TCP slow start, congestion avoid, fast retransmission, UDP None
  • Transmission efficiency: TCP is slow and UDP is fast

Application scenarios

TCP: mail, QQ file transfer, browser UDP: QQ voice, QQ video, live

6.OSI seven-layer model

From bottom to top: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer

TCP/UDP is at the transport layer

IP resides at the network layer

7. What is the DNS protocol? DNS query complete process

DNS

The domain name System (DNS) is an Internet service that translates domain names to IP addresses.

The domain name

A domain name has a hierarchical structure, which is divided into root domain name, top-level domain name (net, com, org, edu, cn), secondary domain name, and tertiary domain name 、、、、 from top to bottom

www.xxx.com: WWW is the third-level domain name, XXX is the second-level domain name, and com is the top-level domain name

There is a domain name server at each level of the domain name, in addition to the computer’s default local domain name server

DNS Query Mode

  • Recursive query

  • Iterative query

Domain name cache

Two types of caching

  • Browser cache
  • Operating system cache (user-configured host file)

Domain name Resolution Process

  • Search DNS cache, first browser cache, then operating system cache
  • Request the local domain name server, the local domain name is expected to recursively query its DNS cache, search success returns the result
  • The local DNS server sends a request to the root DNS server, and the root server returns the TOP-LEVEL DNS server address to the local server
  • The local server sends a request to the top-level domain name server to obtain the IP address of the permission server
  • The local server sends a request to the permission server for the final IP address
  • The local server returns the IP address to the operating system and caches its OWN IP address
  • The operating system returns the IP address to the browser and caches it
  • The browser gets the IP address and caches it

8.CDN

Content delivery networks. The intelligent virtual network built on the basis of the existing network relies on the edge servers deployed in various places, through the central platform of load balancing, content distribution, scheduling and other functional modules, users get the content nearby, reduce network congestion, improve user access response speed and hit ratio.

The key technology

  • Load balancing
  • Caching technology

The principle of analysis

Before the CDN is applied, DNS queries return the IP address of the target server

After the CDN is applied, the DNS query returns a Cannonical Name (CNAME) alias record pointing to the global load balancer of the CDN

CNAME plays the role of middleman in domain name resolution and is the key to realize CDN

Load balancing system

If no IP address is returned, the local DNS sends a request to the load balancing system, and the global load balancing system performs intelligent scheduling

  • According to the USER’s IP address, search the table to get the geographical location and find the nearest edge node
  • Look at the user’s carrier network and find the edge nodes of the same network
  • Check the load status of edge nodes and find nodes with light load

Find the most suitable edge node comprehensively and return this node to the user, so that the user can access the CDN cache nearby

The caching proxy

The cache system can be divided into level 1 cache node and level 2 cache node. Level 1 cache node configuration is higher, directly connected to the source station; Level 2 cache nodes have a lower configuration and are directly connected to users.

Level-2 caches only search level-1 caches when they return to the source. Level-1 caches return to the source only when they do not return to the source, which can effectively reduce the real source.

CDN service quality index

  • Back to the source rate
  • shooting

9. Http1.0/1.1/2.0 differences

HTTP1.0

  • No connection, no status (each request establishes a TCP connection with the server, and closes after the request is completed)
  • Only GET and POST requests are supported

HTTP1.1

  • Support for Connection: keep-alive by default (multiple HTTP requests and responses can be sent over a TCP Connection)
  • The client is allowed to send the next request pending the completion of one request, but the server must return the results in the order requested by the client
  • – Added more request and response headers (last-Modified, if-Modified-since, Etag, if-none-match, etc.) to control cache policy
  • Range is introduced to allow a request for a portion of a resource
  • Introduce host, virtual host
  • Added put, DELETE, and Option requests

HTTP2.0

  • multiplexing

HTTP1.1, multiple requests are sent over a TCP connection in order. But HTTP2.0, in a TCP connection, both the client and the server can send requests without ordering them, avoiding “head congestion”.

  • Binary framing

Frames are the smallest unit of communication in HTTP2.0. HTTP2.0 only transmits data in binary format, not 1.x text format, which is better parsed

  • The first compression

Reduce redundant data, reduce transmission volume and reduce overhead

  • Server push

Allows the server to push messages to clients

10. The HTTP status code

  • 100: Used for POST big data transmission. Before transmission, the server is consulted whether to process POST data
  • 200: success
  • 206: Breakpoint continuation, video large file loading
  • 301: Permanent redirection (often used to replace old and new domain names)
  • 302: Temporary redirection (often used to redirect an unlogged page to a logged page)
  • 304: Negotiated cache (tells the client to directly use the data in the cache, returns only header information, no content)
  • 400: The parameter is incorrect and cannot be identified by the server
  • 401: not logged in
  • 403: Disable access (for example, some resources that only the Intranet can access)
  • 404: The resource path is incorrect
  • 503: The server is down for maintenance, using 503 to respond to requests
  • 504: The gateway times out

11.GET and POST requests

  • A resource request can be obtained by GET or submitted by POST
  • Carry parameters: GET on the URL, POST on the body
  • Limit the size of parameters: GET 2kb and POST unlimited
  • Security: POST is more secure than GET because the data is not visible in the address bar (but plaintext transfers are not secure from a transport point of view)

12. Why does TCP require three handshakes and four waves

Three-way handshake

To establish a TCP connection, the client and server need to send a total of three packets

The function is to confirm whether the receiving and sending capabilities of both parties are normal, and specify their initial serial numbers to prepare for the subsequent reliable transmission

First handshake: The client sends a SYN packet and specifies the INITIAL SEQUENCE number of the client

Second handshake: The server responds with its OWN SYN packet. To acknowledge the CLIENT’s SYN packet, the ISN + 1 of the client is used as the ACK value

Third handshake: The client sends an ACK packet with the ISN + 1 of the server

Four times to wave

First wave: The client sends a FIN packet with a sequence number

Second wave: The server receives a FIN packet and sends an ACK packet with the sequence number of the client plus 1

Third wave: If the server also wants to disconnect, it sends a FIN packet specifying a sequence number to the client

Fourth wave: The client sends an ACK packet with the sequence number of the server +1

13. Understanding of WebSocket

Is a network protocol, application layer protocol. Full-duplex communication can be implemented over a single TCP connection, saving server resources and bandwidth and achieving real-time communication

The client and server only need to complete a handshake to establish persistent communication and two-way data transfer

Websocket previously implemented real-time communication as polling

Ws and WSS represent the plaintext and ciphertext websocket protocols respectively, and the default port is 80 or 443, almost the same as HTTP

advantages

Compared to HTTP: stronger real-time, keep-connected state (no need to carry identity information every time), smaller overhead (smaller packet header protocol)

Application scenarios

  • barrage
  • Media chat
  • Sports Live update
  • Real-time updates of stock fund quotes