[Nginx 02] HTTP protocol Super Comments

Introduction to the HTTP protocol

Hypertext Transfer Protocol (English: H yper T EXT T ransfer P rotocol, abbreviation: HTTP) is an application layer protocol distributed, collaborative, hypermedia information systems. HTTP is the underlying data communication the World Wide Web.

HTTP development by Tim Berners - Lee in 1989, initiated by the European Organization for Nuclear Research (CERN). HTTP standards development is coordinated by the World Wide Web Consortium (World Wide Web Consortium, W3C) and the Internet Engineering Task Force (Internet Engineering Task Force, IETF), finally issued a series of RFC, most famous of which is published in June 1999 RFC 2616, defines the HTTP protocol version --HTTP 1.1 in wide use today.

December 2014, the Internet Engineering Task Force (IETF) in the Hypertext Transfer Protocol Bis (httpbis) Working Group will HTTP / 2 standard proposal submitted to the IESG for discussion, was approved on February 17, 2015. HTTP / 2 standard in May 2015 to RFC 7540 was published, to replace HTTP 1.1 HTTP implementations become standard.

HTTP protocol overview

HTTP is a client terminal (user) and server (website) request and response standard (TCP). By using a web browser, web crawler or other tools, the client initiates a request to the HTTP server on the specified port (default port 80). We call this client is a user agent (user agent). Some resources are stored on the server responses, such as HTML files and images. We call this the response server as the source server (origin server). Multiple "intermediate layer" in the middle of the user agent and the origin server may, for example a proxy server, a gateway, or tunnel (tunnel).

Although the TCP / IP protocol is the Internet's most popular applications, HTTP protocol, there is no requirement to use it or it supports layers. In fact, HTTP can be on any Internet protocol, or achieve other networks. HTTP is assumed that the lower layer provides a reliable transport protocol. Therefore, any agreement to provide such assurances may be its use. Thus it is using TCP as its transport layer in the TCP / IP protocol suite.

Typically, the HTTP client initiates a request to the server to create a designated port (default port 80) TCP connection. HTTP server requests that the client listening port. Upon receiving a request, the server returns a status to the client, such as "HTTP / 1.1 200 OK", and the returned content, the file, an error message such as a request, or other information.

HTTP works

HTTP protocol defines how Web client-side requests a Web page from the Web server and the server how to transfer a Web page to the client. HTTP protocol uses a request / response model. The client sends the server a request packet, the method comprising the requested request packet, URL, protocol version, and requested data request header. A server response status line, including the contents of the protocol version response, success or error code, the server information, the response header and the response data.

The following is a step of HTTP request / response:

\ 1. The client connects to the Web server
a HTTP client, typically a browser, Web server with HTTP port (default is 80) to establish a TCP socket connection. For example, http://www.luffycity.com .

\ 2. HTTP request
sent by a TCP socket text, client request message to the Web server, a request packet by the request line, request headers, blank lines, and 4 parts request data.

\ 3. HTTP server accepts the request and returns the response to
the Web server parses request, locate the requested resource. The copy of the resource server writes a TCP socket, read by the client-side. A response line from the state, in response to the head, and blank lines in response to data 4 parts.

\ 4 releases the connection TCP connection.
If the connection mode is close, then the server closes a TCP connection, the client passive close the connection, the release of a TCP connection; if the connection mode keepalive, then the connection will remain for some time, during which time you can continue receiving a request;

\ 5. The client browser parses the HTML content
client browser status line resolved first, to see that the request is successful status code. Then parse each response header, the response header to inform the character set of HTML documents and document several bytes. The client browser reads the HTML response data, formatted according to its HTML syntax, and displayed in the browser window.

For example: Type the URL in the browser address bar, then press Enter to go through the following process:

  1. Browser request to the DNS server to resolve the domain name in the URL corresponding to IP addresses;
  2. After parsing the IP address of the TCP connection establishment according to the IP address and the default port 80, and the server;
  3. Issues a read file browser (URL domain name corresponding to the rear portion of the file) of the HTTP request, the request packet as a TCP three-way handshake packets of the third data to the server;
  4. The server responds to the browser request, and sends the html text corresponding to the browser;
  5. Release the TCP connection;
  6. Html text and the browser displays the contents;  

  

  img

  http protocol is an application layer protocol on top of TCP / IP protocol.

  Based on the request - response model

    HTTP protocol that a request sent from the client, the server responds to the last request and returns. In other words, definitely start start establishing communications client, the server does not send a response until a request is received

    img

  Stateless save

    HTTP is a non-save state, i.e., no state (Stateless) protocol. HTTP protocol itself does not request and the communication status between the response stored. That this level in the HTTP, a protocol for sending requests or responses had nothing lasting treatment.

    img

    Using the HTTP protocol, whenever a new request is sent, it will produce a corresponding new response. The agreement itself does not keep everything before the request or response information packet. This is to handle a large number of transactions quickly, to ensure that the protocol scalability, and the HTTP protocol specifically designed to be so simple. However, as the Web continues to develop, because there is no state which led to business processing becomes difficult cases increased. For example, a user logs on to a shopping site, even after he jumps to the other page of the station, but also need to be able to continue to stay logged in. For this example, the site is to be able to grasp who sent the request, the need to preserve the user's status. HTTP / 1.1 is a stateless protocol, although, in order to realize a desired function to maintain state, then the introduction of Cookie technology. With Cookie and then HTTP protocol communication, you can manage the state. For more information about Cookie explain later.

  no connection

    Meaning No connection is to limit the processing only one request per connection. After the server processes client requests and receives the customer's response, i.e., disconnected. In this way it can save transmission time, and can improve concurrency, can not establish a lasting connection and each user request once the appropriate time, and client service was discontinued. But no connection in two ways, after early http protocol is a request for a response, directly off, but now is not the http protocol version 1.1 directly disconnected, but wait a few seconds, those few seconds so what it is, users waiting for the subsequent operation, if the user has a new request within a few seconds of this, it is still before the passage through the connection to send and receive messages over a few seconds if the user does not send a new request, it will disconnect, this can increase the efficiency and reduce the number of times within a short time to establish the connection because a connection is time-consuming, the default seems to be in three seconds now, but this time we are through the back-end code to adjust themselves according to their website site user behavior to analyze the statistics of an optimum waiting time.

The method of HTTP request

HTTP / 1.1 protocol defines eight methods the CCP (also called "action") to operate the specified resource in different ways:

GET

Issued a "show" to the specified resource request. GET method should only be used in the read data should not be used to generate the "side effects" of operation, for example in the Web Application. One reason is that GET may be free to access the network spiders.

As with the GET method, are specified resource request to the server. But the server will not be passed back to the resource section of this article. Its advantage is that you can use this method without having to transfer the entire contents of which you can obtain "information on the resource" (or meta-information called metadata).

POST

Submit data to specify the resource, the server for processing the request (e.g., to submit a form or upload files). Data contained in the request herein. This request may create new resources or modify existing resources, or both.

PUT

To upload their content to the latest specified resource location.

DELETE

Requests that the server delete the resource identified by the Request-URI.

TRACE

Echo request received by the server, mainly for testing or diagnosis.

OPTIONS

This method enables the server to return all the HTTP request methods supported by the resource. With '*' instead of the resource name, the OPTIONS request is sent to the Web server, you can test the server functions are normal operation.

CONNECT

HTTP / 1.1 protocol can be reserved for connection to the proxy server pipeline mode. Link (via unencrypted HTTP proxy server) is commonly used SSL encryption server.

Precautions:

  1. Method names are case-sensitive. When a request for a resource does not support the corresponding request method, the server should return a status code 405 (Method Not Allowed), when the server does not know or does not support the corresponding request method should return a status code 501 (Not Implemented).
  2. HTTP server should implement at least the GET and HEAD methods, other methods are optional. Of course, all of the implementation are supported by the following methods should match each semantic definitions. In addition to the above-described method, a specific HTTP server extension method can also be customized. For example the PATCH (method specified by RFC 5789) for topical application to modify the resource .

Request method: get and post request (form by form to write our own watch)

  • Data GET submitted after will be placed URL, which is the request line inside to? Segmentation URL and transmit data to & connected between parameters, such as EditBook? Name = test1 & id = 123456. (Request header inside the content-type to do such parameters form, later speaking) is the data submitted by the POST method of HTTP packet in the request body.

  • GET submitted the data size is limited (because the browser restrictions on the length of the URL), and the data submitted by the POST method is not limited.

  • GET and POST requests in the server request for acquiring data in different ways, it is time to take our own request data on the server in different ways, and expensive nonsense phrase.

HTTP status code

All of the first row are HTTP response status line, followed by the current version of HTTP, three-digit status code, and a description of the state of phrases, each other separated by a space.

The first digit status code representing the type of the current response:

  • 1xx message - the server request has been received, processing continues
  • 2xx Success - server request has been received successfully, understood, and accepted
  • 3xx Redirection - Next Steps need to complete this request
  • Request 4xx error - request containing the lexical error or can not be executed
  • 5xx Server Error - Server error occurred while processing a request properly

Although in RFC 2616 describe the state of the phrase have been proposed, for example, "200 OK", "404 Not Found", but still able WEB developer to decide what phrases employed to describe the state or the display localized custom information.

  img

URL

Hypertext Transfer Protocol (HTTP) Uniform Resource Locator Internet to get information from the five basic elements include a simple address:

  • Transfer Protocol.
  • URL level mark symbol (as [//], fixed)
  • Access to resources required credential information (may be omitted)
  • server. (Often a domain name, sometimes as IP address)
  • The port number. (Digitally represented, if the default value is HTTP ": 80" may be omitted)
  • path. (With a "/" character difference between each directory name in the path)
  • Inquire. Form parameters (GET mode, the "?" Character as a starting point, each parameter "&" separated, then "=" parameter name to separate the data, usually a URL-encoded UTF8, and to avoid conflict of character issues )
  • Fragments. With "#" character as a starting point

To http://www.luffycity.com:80/news/index.html?id=250&page=1 for example, in which:

http, is a protocol;
www.luffycity.com, is the server;
80 is the default network port number on the server, not displayed by default;
/news/index.html, is the path (URI: located directly to the corresponding resources);
? id = 250 & page = 1, is the query.
Most web browsers do not require the user to enter the page " HTTP: //" in part because the vast majority of web content is hypertext transfer protocol file. Similarly , "80" is the port number used Hypertext Transfer Protocol file, so usually do not stated. In general, just type the Uniform Resource Locator is part of the user (www.luffycity.com:80/news/index.html?id=250&page=1) on it.

Since the hypertext transfer protocol allows a server to redirect the browser to another page address, the server allows many users will be omitted portion of the web address, such as www. Technically web address of this omission is actually a different web address, the browser itself can not decide whether to pass the new address, the server must complete the redirect task.

HTTP format request (request protocol)

    img

     URL contains: / index / index2 a = 1 & b = 2; and path parameters are here?.

    img

      Request content head inside for example: request data length represents the length of the body inside, other request header inside these key-value pairs, we will continue to talk about, probably know what you can, which has a user-agent, you need to be to remember it, it is to tell your server, what I request you to send used.

      img

      

      Jingdong, for example, look at the user-agent

      img

     img

      See a reptile example, when climbing Jingdong no problem, but the time must climb drawer with user-agent, because of the user-agent drawer did judgment to determine if you are not a normal request, be pocketing mechanism one kind.

      img

      We saved demo.html open the file, and then open the browser will be able to see the page to see the effect.

      Write content above mean to let you know the existence of such a request header, some meaningful request we can also define your own head, just inside the module requests the headers = {}, which add the dictionary on the line.

      

  

HTTP response format (protocol response)

  img

  img

 

Reproduced in: https: //www.cnblogs.com/an-wen/p/11180076.html

Introduction to the HTTP protocol

Hypertext Transfer Protocol (English: H yper T EXT T ransfer P rotocol, abbreviation: HTTP) is an application layer protocol distributed, collaborative, hypermedia information systems. HTTP is the underlying data communication the World Wide Web.

HTTP development by Tim Berners - Lee in 1989, initiated by the European Organization for Nuclear Research (CERN). HTTP standards development is coordinated by the World Wide Web Consortium (World Wide Web Consortium, W3C) and the Internet Engineering Task Force (Internet Engineering Task Force, IETF), finally issued a series of RFC, most famous of which is published in June 1999 RFC 2616, defines the HTTP protocol version --HTTP 1.1 in wide use today.

December 2014, the Internet Engineering Task Force (IETF) in the Hypertext Transfer Protocol Bis (httpbis) Working Group will HTTP / 2 standard proposal submitted to the IESG for discussion, was approved on February 17, 2015. HTTP / 2 standard in May 2015 to RFC 7540 was published, to replace HTTP 1.1 HTTP implementations become standard.

HTTP protocol overview

HTTP is a client terminal (user) and server (website) request and response standard (TCP). By using a web browser, web crawler or other tools, the client initiates a request to the HTTP server on the specified port (default port 80). We call this client is a user agent (user agent). Some resources are stored on the server responses, such as HTML files and images. We call this the response server as the source server (origin server). Multiple "intermediate layer" in the middle of the user agent and the origin server may, for example a proxy server, a gateway, or tunnel (tunnel).

Although the TCP / IP protocol is the Internet's most popular applications, HTTP protocol, there is no requirement to use it or it supports layers. In fact, HTTP can be on any Internet protocol, or achieve other networks. HTTP is assumed that the lower layer provides a reliable transport protocol. Therefore, any agreement to provide such assurances may be its use. Thus it is using TCP as its transport layer in the TCP / IP protocol suite.

Typically, the HTTP client initiates a request to the server to create a designated port (default port 80) TCP connection. HTTP server requests that the client listening port. Upon receiving a request, the server returns a status to the client, such as "HTTP / 1.1 200 OK", and the returned content, the file, an error message such as a request, or other information.

HTTP works

HTTP protocol defines how Web client-side requests a Web page from the Web server and the server how to transfer a Web page to the client. HTTP protocol uses a request / response model. The client sends the server a request packet, the method comprising the requested request packet, URL, protocol version, and requested data request header. A server response status line, including the contents of the protocol version response, success or error code, the server information, the response header and the response data.

The following is a step of HTTP request / response:

\ 1. The client connects to the Web server
a HTTP client, typically a browser, Web server with HTTP port (default is 80) to establish a TCP socket connection. For example, http://www.luffycity.com .

\ 2. HTTP request
sent by a TCP socket text, client request message to the Web server, a request packet by the request line, request headers, blank lines, and 4 parts request data.

\ 3. HTTP server accepts the request and returns the response to
the Web server parses request, locate the requested resource. The copy of the resource server writes a TCP socket, read by the client-side. A response line from the state, in response to the head, and blank lines in response to data 4 parts.

\ 4 releases the connection TCP connection.
If the connection mode is close, then the server closes a TCP connection, the client passive close the connection, the release of a TCP connection; if the connection mode keepalive, then the connection will remain for some time, during which time you can continue receiving a request;

\ 5. The client browser parses the HTML content
client browser status line resolved first, to see that the request is successful status code. Then parse each response header, the response header to inform the character set of HTML documents and document several bytes. The client browser reads the HTML response data, formatted according to its HTML syntax, and displayed in the browser window.

For example: Type the URL in the browser address bar, then press Enter to go through the following process:

  1. Browser request to the DNS server to resolve the domain name in the URL corresponding to IP addresses;
  2. After parsing the IP address of the TCP connection establishment according to the IP address and the default port 80, and the server;
  3. Issues a read file browser (URL domain name corresponding to the rear portion of the file) of the HTTP request, the request packet as a TCP three-way handshake packets of the third data to the server;
  4. The server responds to the browser request, and sends the html text corresponding to the browser;
  5. Release the TCP connection;
  6. Html text and the browser displays the contents;  

  

  img

  http protocol is an application layer protocol on top of TCP / IP protocol.

  Based on the request - response model

    HTTP protocol that a request sent from the client, the server responds to the last request and returns. In other words, definitely start start establishing communications client, the server does not send a response until a request is received

    img

  Stateless save

    HTTP is a non-save state, i.e., no state (Stateless) protocol. HTTP protocol itself does not request and the communication status between the response stored. That this level in the HTTP, a protocol for sending requests or responses had nothing lasting treatment.

    img

    Using the HTTP protocol, whenever a new request is sent, it will produce a corresponding new response. The agreement itself does not keep everything before the request or response information packet. This is to handle a large number of transactions quickly, to ensure that the protocol scalability, and the HTTP protocol specifically designed to be so simple. However, as the Web continues to develop, because there is no state which led to business processing becomes difficult cases increased. For example, a user logs on to a shopping site, even after he jumps to the other page of the station, but also need to be able to continue to stay logged in. For this example, the site is to be able to grasp who sent the request, the need to preserve the user's status. HTTP / 1.1 is a stateless protocol, although, in order to realize a desired function to maintain state, then the introduction of Cookie technology. With Cookie and then HTTP protocol communication, you can manage the state. For more information about Cookie explain later.

  no connection

    Meaning No connection is to limit the processing only one request per connection. After the server processes client requests and receives the customer's response, i.e., disconnected. In this way it can save transmission time, and can improve concurrency, can not establish a lasting connection and each user request once the appropriate time, and client service was discontinued. But no connection in two ways, after early http protocol is a request for a response, directly off, but now is not the http protocol version 1.1 directly disconnected, but wait a few seconds, those few seconds so what it is, users waiting for the subsequent operation, if the user has a new request within a few seconds of this, it is still before the passage through the connection to send and receive messages over a few seconds if the user does not send a new request, it will disconnect, this can increase the efficiency and reduce the number of times within a short time to establish the connection because a connection is time-consuming, the default seems to be in three seconds now, but this time we are through the back-end code to adjust themselves according to their website site user behavior to analyze the statistics of an optimum waiting time.

The method of HTTP request

HTTP / 1.1 protocol defines eight methods the CCP (also called "action") to operate the specified resource in different ways:

GET

Issued a "show" to the specified resource request. GET method should only be used in the read data should not be used to generate the "side effects" of operation, for example in the Web Application. One reason is that GET may be free to access the network spiders.

As with the GET method, are specified resource request to the server. But the server will not be passed back to the resource section of this article. Its advantage is that you can use this method without having to transfer the entire contents of which you can obtain "information on the resource" (or meta-information called metadata).

POST

Submit data to specify the resource, the server for processing the request (e.g., to submit a form or upload files). Data contained in the request herein. This request may create new resources or modify existing resources, or both.

PUT

To upload their content to the latest specified resource location.

DELETE

Requests that the server delete the resource identified by the Request-URI.

TRACE

Echo request received by the server, mainly for testing or diagnosis.

OPTIONS

This method enables the server to return all the HTTP request methods supported by the resource. With '*' instead of the resource name, the OPTIONS request is sent to the Web server, you can test the server functions are normal operation.

CONNECT

HTTP / 1.1 protocol can be reserved for connection to the proxy server pipeline mode. Link (via unencrypted HTTP proxy server) is commonly used SSL encryption server.

Precautions:

  1. Method names are case-sensitive. When a request for a resource does not support the corresponding request method, the server should return a status code 405 (Method Not Allowed), when the server does not know or does not support the corresponding request method should return a status code 501 (Not Implemented).
  2. HTTP server should implement at least the GET and HEAD methods, other methods are optional. Of course, all of the implementation are supported by the following methods should match each semantic definitions. In addition to the above-described method, a specific HTTP server extension method can also be customized. For example the PATCH (method specified by RFC 5789) for topical application to modify the resource .

Request method: get and post request (form by form to write our own watch)

  • Data GET submitted after will be placed URL, which is the request line inside to? Segmentation URL and transmit data to & connected between parameters, such as EditBook? Name = test1 & id = 123456. (Request header inside the content-type to do such parameters form, later speaking) is the data submitted by the POST method of HTTP packet in the request body.

  • GET submitted the data size is limited (because the browser restrictions on the length of the URL), and the data submitted by the POST method is not limited.

  • GET and POST requests in the server request for acquiring data in different ways, it is time to take our own request data on the server in different ways, and expensive nonsense phrase.

HTTP status code

All of the first row are HTTP response status line, followed by the current version of HTTP, three-digit status code, and a description of the state of phrases, each other separated by a space.

The first digit status code representing the type of the current response:

  • 1xx message - the server request has been received, processing continues
  • 2xx Success - server request has been received successfully, understood, and accepted
  • 3xx Redirection - Next Steps need to complete this request
  • Request 4xx error - request containing the lexical error or can not be executed
  • 5xx Server Error - Server error occurred while processing a request properly

Although in RFC 2616 describe the state of the phrase have been proposed, for example, "200 OK", "404 Not Found", but still able WEB developer to decide what phrases employed to describe the state or the display localized custom information.

  img

URL

Hypertext Transfer Protocol (HTTP) Uniform Resource Locator Internet to get information from the five basic elements include a simple address:

  • Transfer Protocol.
  • URL level mark symbol (as [//], fixed)
  • Access to resources required credential information (may be omitted)
  • server. (Often a domain name, sometimes as IP address)
  • The port number. (Digitally represented, if the default value is HTTP ": 80" may be omitted)
  • path. (With a "/" character difference between each directory name in the path)
  • Inquire. Form parameters (GET mode, the "?" Character as a starting point, each parameter "&" separated, then "=" parameter name to separate the data, usually a URL-encoded UTF8, and to avoid conflict of character issues )
  • Fragments. With "#" character as a starting point

To http://www.luffycity.com:80/news/index.html?id=250&page=1 for example, in which:

http, is a protocol;
www.luffycity.com, is the server;
80 is the default network port number on the server, not displayed by default;
/news/index.html, is the path (URI: located directly to the corresponding resources);
? id = 250 & page = 1, is the query.
Most web browsers do not require the user to enter the page " HTTP: //" in part because the vast majority of web content is hypertext transfer protocol file. Similarly , "80" is the port number used Hypertext Transfer Protocol file, so usually do not stated. In general, just type the Uniform Resource Locator is part of the user (www.luffycity.com:80/news/index.html?id=250&page=1) on it.

Since the hypertext transfer protocol allows a server to redirect the browser to another page address, the server allows many users will be omitted portion of the web address, such as www. Technically web address of this omission is actually a different web address, the browser itself can not decide whether to pass the new address, the server must complete the redirect task.

HTTP format request (request protocol)

    img

     URL contains: / index / index2 a = 1 & b = 2; and path parameters are here?.

    img

      Request content head inside for example: request data length represents the length of the body inside, other request header inside these key-value pairs, we will continue to talk about, probably know what you can, which has a user-agent, you need to be to remember it, it is to tell your server, what I request you to send used.

      img

      

      Jingdong, for example, look at the user-agent

      img

     img

      See a reptile example, when climbing Jingdong no problem, but the time must climb drawer with user-agent, because of the user-agent drawer did judgment to determine if you are not a normal request, be pocketing mechanism one kind.

      img

      We saved demo.html open the file, and then open the browser will be able to see the page to see the effect.

      Write content above mean to let you know the existence of such a request header, some meaningful request we can also define your own head, just inside the module requests the headers = {}, which add the dictionary on the line.

      

  

HTTP response format (protocol response)

  img

  img

 

Reproduced in: https: //www.cnblogs.com/an-wen/p/11180076.html

Guess you like

Origin www.cnblogs.com/boyYu/p/12463937.html