Weekly share of the two HTTP protocol (1)

Source: Internet
Author: User

This sharing HTTP protocol, divided into three parts, this is the first part, mainly on the development of HTTP, each version, as well as the characteristics of each version.

One: http/0.9

The earliest version was released in 1991 as version 0.9. This version is extremely simple and has only one command GET . Only the client is allowed to send a GET request, and the request header is not supported. Because there is no protocol header, the HTTP 0.9 protocol supports only one content, that is, plain text. However, the Web page still supports formatting in HTML language and cannot insert images.

eg

Get/index.html

The above command indicates that after a TCP connection (connection) is established, the client requests a Web page from the server index.html .

The protocol specifies that the server can only return strings in HTML form and cannot return other formats

<div>hello world</div>

The server closes the TCP connection after it is sent.

It can be known that the http/0.9 version of HTTP has shown the stateless nature.

Two: http/1.0

May 1996, the http/1.0 release, the content greatly increased.

First, content in any format can be sent. This allows the Internet not only to transfer text, but also to transfer images, video, binary files. This laid the foundation for the great development of the Internet.

Second, in addition to the GET command, but also introduced POST commands and HEAD commands, enriched the browser and the server interactive means.

Again, the format of the HTTP request and response has changed. In addition to the data section, each communication must include the header information (HTTP header), which is used to describe some meta-data.

Other new features include status code, multi-character set support, multipart send (multi-part type), permissions (authorization), caching (cache), content encoding (contents encoding), and more.

eg

Client AH out request:

get/http/1.0

User-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)

Accept: */*

  

Server-side response:

    HTTP/1.0 200 OK

    Content-Type: text/plain

    Content-Length: 137582

    Expires: Thu, 05 Dec 1997 16:00:00 GMT

    Last-Modified: Wed, 5 August 1996 15:55:28 GMT

    Server: Apache 0.84

<HTML>

<body>hello world</body>

    

Three: http/1.1

  In January 1997, the http/1.1 version was released only half a year later than the 1.0 version. It further improved the HTTP protocol, which has been used 20 years later today, and is still the most popular version.

HTTP 1.1 introduces many key performance optimizations: KeepAlive connection (persistent connection), chunked encoding transmission, byte-range request, request pipeline (pipeline mechanism), etc.

    • KeepAlive

Allows the HTTP device to keep the TCP connection in an open state after the transaction has ended, reusing the current connection for future HTTP requests until the client or server decides to close it.

All connections in HTTP 1.1 are long connections by default, unless special claims are not supported (Connection:close).

Currently, for the same domain name, most browsers allow the simultaneous creation of 6 persistent connections.

    • chunked encoded transmission

As long as the header information of the request or response has a Transfer-Encoding field, it indicates that the response will consist of an undetermined number of data blocks.

This encoding transmits the entity chunked and indicates the length of the block, until the length of 0 blocks indicates the end of the transfer, which is particularly useful when the entity length is unknown (such as data generated dynamically by the database).

    • BYTE range Request 

HTTP1.1 supports the transfer of part of the content. For example, when the client already has a portion of the content, in order to save bandwidth, you can request only a portion of the server. This feature is implemented by introducing a range header field in the request message, which allows only a portion of the resource to be requested.

 · Piping mechanism

version 1.1 also introduces a pipeline mechanism (pipelining), in which the client can send multiple requests simultaneously in the same TCP connection. This further improves the efficiency of the HTTP protocol. For example, a client needs to request two resources. Previously, in the same TCP connection, send a request first, and then wait for the server to respond, receive and then issue a B request. The pipeline mechanism is to allow the browser to issue a and B requests at the same time, but the server is in order, the first response to a request, complete and then respond to the B request.

  

HTTP 1.1 also adds the following features:

      • Both the request message and the response message should support the host header domain
        In HTTP1.0, each server is considered to be bound to a unique IP address, so the URL in the request message does not have a host name (hostname). However, with the development of virtual host technology, multiple virtual hosts (multi-homed Web Servers) can exist on a physical server, and they share an IP address. Therefore, the introduction of the host header is necessary.
      • Added a batch of request method
        HTTP1.1 added Options,put, DELETE, TRACE, connect method
      • Cache processing
        http/1.1 added some new features to the cache based on 1.0, introducing entity tags, commonly called e-tags, and adding a more powerful Cache-control header.
Four: Http/2

2015, HTTP/2 released. It is not called http/2.0, because the standard Committee does not intend to release the child version again, the next new version will be HTTP/3.

HTTP/2 adds the following features

• Binary protocol

http/1.1 version of the header information is definitely text (ASCII encoding), the data body can be text, or it can be binary. HTTP/2 is a complete binary protocol in which the header information and data bodies are binary and collectively referred to as "frames": header information frames and data frames.

One benefit of the binary protocol is that additional frames can be defined. HTTP/2 defines nearly 10 types of frames, providing a foundation for future advanced applications. If you use text to do this, parsing the data becomes cumbersome, and binary parsing is much more convenient.

• retasking

HTTP/2 multiplexing TCP connections, in which both the client and the browser can send multiple requests or responses at the same time, and do not correspond in order one by one, thus avoiding "team head clogging".

For example, in a TCP connection, the server received both a request and a B request, so the first response to a request, the results found that the processing process is very time-consuming, so send a request has been processed parts, and then respond to the B request, after completion, then send a request the remainder.

This two-way, real-time communication, is called the multi-Work (multiplexing).

• Data Flow

Because HTTP/2 packets are sent out of sequence, successive packets within the same connection may belong to different responses. Therefore, the packet must be marked to indicate which response it belongs to.

HTTP/2 will each request or response of all packets, called a stream. Each data stream has a unique number. When a packet is sent, the data stream ID must be marked to distinguish which data stream it belongs to. In addition, the client sends out the data stream, the ID is all odd, the server issued, the ID is even.

When the data stream is sent in half, both the client and the server can send a signal ( RST_STREAM frame) to cancel the traffic. Version 1.1 The only way to cancel the data flow is to close the TCP connection. This means that HTTP/2 can cancel a request, while ensuring that the TCP connection is still open and can be used by other requests.

The client can also specify the priority of the data flow. The higher the priority, the sooner the server responds.

• Header information Compression

The HTTP protocol does not have a status, and each request must have all the information attached. Therefore, many of the requested fields are duplicates, such as Cookie and User Agent , exactly the same content, each request must be accompanied, which will waste a lot of bandwidth, also affect the speed.

HTTP/2 has optimized this point by introducing the header information compression mechanism (header compression). On the one hand, the header information is used gzip or compress compressed before sending; On the other hand, the client and the server maintain a header information table, all the fields are stored in the table, generate an index number, and then do not send the same field, only send the index number, which increases the speed.

• Server Push

TTP/2 allows the server to proactively send resources to clients without request, which is called Server push.

A common scenario is a client requesting a Web page that contains a lot of static resources. Normally, the client must receive the Web page, parse the HTML source, find a static resource, and then issue a static resource request. In fact, the server can expect the client to request the Web page, it is likely to request static resources, so they proactively send these static resources along with the Web page to the client.

Weekly share of the two HTTP protocol (1)

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.