Arrangement of http Protocol Knowledge Points (Not Periodically Updated)

  Front end, http

I have been working as a front-end development engineer for some time. I have mastered “front-end knowledge”, that is, the so-called “html+css+javascript” and their extensions, but the more basic knowledge beyond this is extremely weak.
Thanks to my former boss’s comments and suggestions, I realized that I still have a lot of knowledge that needs to be supplemented urgently. Taking advantage of the good opportunity to return to school recently, I went to the library to catch up on the knowledge of http protocol.
This article is used to record my knowledge points of learning http protocol, which may be interspersed with some interview questions. It is updated from time to time. Welcome to pay attention ~

1. What is http Protocol

HyperText Transfer Protocol (HTTP) is the most widely used network protocol on the Internet. HTTP was originally designed to provide a way to publish and receive HTML pages. Resources requested through HTTP or HTTPS protocols are identified by Uniform Resource Identifiers (URI).
(From Wikipedia)

The main concepts are as follows:

  • Connection: The actual circulation of the transport layer, established between two applications that communicate with each other.

  • Message: basic communication unit, transmitted through connection.

  • Request: request information from the client to the server, including the method applied to the resource, the identifier of the resource, and the version number of the protocol.

  • Response: The information returned from the server includes the version number of the HTTP protocol, the status of the request (such as “successful” or “not found”) and the MIME type of the document.

  • Resource: A network data object or service identified by a URI.

  • EMity: A special representation of a data resource or a reflection from a service resource that may be enclosed in a request or response message. The entity includes the entity header information and the entity’s own content.

  • Client: An application that establishes a connection to send a request.

  • Useragent: Initializes the requested customer. They can be browsers, editors, or other user tools.

  • Server: An application that accepts connections and returns information to requests.

  • Proxy: An intermediate program that can act as a server or as a client to establish requests for other clients. The request is transmitted to other servers internally or through possible translation.

  • Gateway: A server that serves as an intermediary between other servers. Different from the proxy, the gateway accepts the request as if it were the source server for the requested resource. The requesting client does not realize that it is deali ng with the gateway. Gateways often serve as server-side portals through firewalls, and gateways can also serve as protocol translators to access resources stored in non-HTTF systems.

(From) utm_source=tuicool&utm_medium=referral)

2, from the input address to the process of receiving data

In general, the address we enter in the browser address bar may be clicking jump, you will see the corresponding page. But what is the middle process? First, let’s analyze this address and see what parts it is made up of-

  • Http: It means to locate network resources through HTTP protocol;

  • domain name of the host visited;

  • 2016/01/19/markcook-development: specifies the URI of the requested resource.

To sort it out, it is actually

Protocol Type://Host Domain Name (or IP Address): Port (Default)/Resource Path/

After entering the web address and clicking jump, the browser and server will perform a series of tasks:

  • If you enter the URL host domain name, DNS resolution will be performed to resolve the domain name into IP address and port, and then a TCP link will be established with it.

  • If the input URL is IP address and port, a TCP connection will be established directly with it.

  • The browser sends an http request message with information to the server, including identity verification, list of resources to be requested, etc.

  • The server receives the request and then processes (responds).

  • The server returns the processed http response message to the browser.

  • Close TCP connection.

  • The browser processes the response message, renders it on the page, and finally presents it to the user.

Each step involves more complicated contents. We will understand the process for the time being and then study it slowly.

3. The difference and relation between URI, URL and URN

  • URI(Uniform Resource Identifier): uniform resource identifier. Used to uniquely identify a resource.

  • URL(Uniform Resource Locator): uniform resource locator. It is a specific URI that indicates that the resource is found through the path.

  • URN(Uniform Resource Name): Uniform resource name. It is also a specific URI that indicates that the resource is found by name.

To sum up, URLs and URNs are subsets, and URIs are now mostly equivalent to URLs.

4. Message

Http messages are data blocks sent between http applications. Messages are divided into two types, one is a request message and the other is a response message. Their composition can be divided into three parts: starting line, header and main body.

  • Request message
    The format is generally

 GET/path/xxx.gif HTTP/1.0
  • Response message
    The format is generally

 HTTP/1.0 200 OK
 Content-Type: image/gif
 Content-length: 8572
 [A Picture]

The following is a brief description of each part

1. Start line
The starting line of the request message statesWhat to do; The starting line of the response message statesWhat happened?

  • Method
    The client wants the server to perform actions on the resource, such as GET, POST, DELETE, etc.

  • Request-url
    Named the requested resource or the full URL of the URL path component.

  • Version
    The http version used by the message looks like this: HTTP/ < major version number >. < minor version number >

  • Status-code
    Such as 200 shown as successful, 302 redirected, 404 inaccessible, etc., the status code will be described in detail later.

  • Reason-phrase
    The readable version of the state code can be understood as a description of the state and readable to human beings.

2. Header
The header mainly stores some additional information about the message, such asContent-Type: image/gif, which explains the MIME type of the main part, and similarly, the response time of the server, the file types that the client can receive, etc.

3. Main body part
Optional. For http to transfer content.

(To be continued. . . )