Home  >  Article  >  Web Front-end  >  Understand HTTP, HTTPS, SPDY, HTTP2 at once

Understand HTTP, HTTPS, SPDY, HTTP2 at once

云罗郡主
云罗郡主forward
2018-11-13 16:20:206013browse


The content of this article is about understanding HTTP, HTTPS, SPDY, and HTTP2 at one time. It has certain reference value and should be used if necessary. Friends can refer to it, I hope it will be helpful to you.

Understand HTTP, HTTPS, SPDY, HTTP2 at once

As a veteran of Internet communication protocols, the HTTP protocol has gone through three version changes today. The latest version is HTTP2.0, which I believe everyone is familiar with. . Today I will give you a good introduction to the past and present of HTTP.

HTTP/0.9

The earliest version of HTTP was born in 1991. This earliest version is extremely simple compared to now, with no HTTP header, no status code, and even version There was no number, and later its version number was set to 0.9 to distinguish it from other versions of HTTP. HTTP/0.9 only supports one method - Get, and the request has only one line.

GET /hello.html
The response is also very simple, only containing the html document itself.

<HTML>
Hello world
</HTML>

When the TCP connection is established, the server returns a string in HTML format to the client. After sending, close the TCP connection. Since there are no status codes and error codes, if an error occurs during server processing, only a special HTML file containing problem description information will be returned. This is the earliest version of HTTP/0.9.

HTTP/1.0

In 1996, the HTTP/1.0 version was released, which greatly enriched the transmission content of HTTP. In addition to text, you can also send pictures, videos, etc. This It laid the foundation for the development of the Internet. Compared with HTTP/0.9, HTTP/1.0 mainly has the following features:

Requests and responses support HTTP headers, status codes are added, and the beginning of the response object is a response status line

Protocol version Information needs to be sent along with the request, supporting HEAD and POST methods

Supports transmitting other types of content besides HTML files

A typical HTTP/1.0 request looks like this:

GET /hello.html HTTP/1.0
User-Agent:NCSA_Mosaic/2.0(Windows3.1)
200 OK
Date: Tue, 15 Nov 1996 08:12:31 GMT
Server: CERN/3.0 libwww/2.17
Content-Type: text/html
<HTML>
一个包含图片的页面
<IMGSRC="/smile.gif">
</HTML>

HTTP/1.1


HTTP/1.1 was released a few months after HTTP/1.0. HTTP/1.1 is more of an improvement on HTTP/1.0. In HTTP1.1, it mainly has the following improvements:

Can reuse connections

Add pipeline: HTTP pipeline is to A technology that submits multiple HTTP requests in batches without waiting for a response from the server during transmission. The pipeline mechanism must be completed through a persistent connection. The browser's batch submission of HTTP requests can greatly shorten the page loading time, especially when the transmission delay (lag/latency) is high. One thing to note is that only idempotent requests can use the pipeline, such as GET and HEAD methods.

Chunked encoding transmission: This encoding transmits the entity in chunks and indicates the length block by block until the length is 0 blocks indicating the end of the transmission. This is particularly useful when the length of the entity is unknown (such as data dynamically generated by the database)

Introduce more cache control mechanisms: such as etag, cache-control

Introduce content negotiation mechanisms, including language, encoding, type, etc., and allow the client and server to agree on the most appropriate Content exchange

Both request messages and response messages support the Host header field: In HTTP1.0, each server is considered to be bound to a unique IP address. Therefore, the URL in the request message does not pass the 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 OPTIONS, PUT, DELETE, TRACE, CONNECT methods

Although HTTP/1.1 has been optimized in many points, as the most widely used protocol version, it can already satisfy many networks However, as web pages become more and more complex and even evolve into independent applications, HTTP/1.1 gradually exposes some problems:

When transmitting data, the connection must be re-established every time, which is The mobile terminal is particularly unfriendly

The transmission content is plain text, which is not secure enough

The header content is too large, and the header does not change much every time the request is made, causing waste

keep-alive to the service The end brings performance pressure

In order to solve these problems, HTTPS and SPDY came into being.

SPDY

In fact, SPDY is not a new protocol, but a session layer before HTTP.

Between 2010 and 2015, Google demonstrated an alternative way of exchanging data between the client and server by implementing an experimental SPDY protocol. It captures the focus of browser and server-side developers, clarifies the increase in response volume and solves the complexity of data transfer. The default goal when starting the SPDY project is:

Reduce page load time (PLT) by 50%.

No need for the website author to modify any content.

Minimize deployment complexity without changing network infrastructure.

Working with the open source community to develop this new protocol.

Collect real performance data to verify whether this experimental protocol is effective.

In order to achieve the goal of reducing page load times, SPDY introduces a new binary framing data layer to enable multi-directional requests and responses, prioritize, minimize and eliminate unnecessary network delays, with the goal of Make more efficient use of underlying TCP connections.

HTTP/2.0

In 2015, HTTP/2.0 came out. Let’s first introduce the characteristics of HTTP/2.0:

Use binary framing layer: Add a binary framing layer between the application layer and the transport layer to achieve the HTTP method without changing the semantics of HTTP. , status code, URI and header fields, break through the performance limitations of HTTP1.1, improve transmission performance, and achieve low latency and high throughput. At the binary framing layer, HTTP2.0 will divide all transmitted information into smaller messages and frames, and encode them in binary format. The header information of HTTP1.x will be encapsulated into the Headers frame, and we The request body is encapsulated into the Data frame.

Binary Framing

Multiplexing: For HTTP/1.x, even if a long connection is enabled, the request is sent serially. When the bandwidth is sufficient, The utilization rate of bandwidth is not enough. HTTP/2.0 adopts multiplexing method, which can send multiple requests in parallel to improve the utilization rate of bandwidth.

Multiplexing

Data flow priority: Since requests can be sent concurrently, if the browser is waiting for key CSS or JS files to complete rendering of the page, the server What should I do if I am focusing on sending picture resources? HTTP/2.0 can set a priority value for data flows. This priority value determines the different priority strategies used by the client and server to process different flows.

Server-side push: In HTTP/2.0, the server can send content other than the request to the client. For example, when a page is being requested, the server will push the page-related logo, CSS and other files directly to the client. , instead of waiting until the request comes before sending it, because the server thinks that the client will use these things. This is equivalent to gathering all resources in one HTML document.

Header compression: Use the header table to track and store previously sent key-value pairs. The same content will not be sent in each request and response.

The above is a complete introduction to understanding HTTP, HTTPS, SPDY, and HTTP2 at one time. If you want to know more about Html5 tutorial, please pay attention to the PHP Chinese website.



The above is the detailed content of Understand HTTP, HTTPS, SPDY, HTTP2 at once. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete