Read "Schematic http" summary--Nineth Chapter

Source: Internet
Author: User
Tags new set

HTTP-based feature append protocol

Although the HTTP protocol is simple and concise, but with the development of the Times, its function of the use of the exhausted State has been highlighted. This article focuses on protocols that are based on the new features of HTTP.


9.1 HTTP-based protocols

In establishing the HTTP standard specification, the creator primarily wanted HTTP as the protocol for transmitting HTML documents. With the development of the Times, the use of the web is more diverse, such as the evolution of online shopping, SNS, enterprises or organizations within the various management tools. Wait a minute. The features pursued by these sites can be implemented through Web applications and scripting programs. In time these functions have been satisfied with the requirements, but the performance is not optimal, due to the limitations of the HTTP protocol and its own limited. The lack of HTTP functionality can be remedied by creating a new set of protocols. However, HTTP-based Web browsers are now used in a global environment and cannot completely abandon HTTP. The rules for some new protocols are HTTP-based, and new features are added on top of that.


9.2 Spdy to eliminate HTTP bottlenecks

Google released the Spdy (from speedy) in 2010, which aims to address HTTP performance bottlenecks and shorten the load time of Web pages (50%). Spdy-the Chromium projects.http://www.chromiunm.org/spdy/


9.2.1 the bottleneck of HTTP

It's also fun to be able to see a huge amount of user-published content in real time on SNS sites like Facebook and Twitter. When hundreds of, tens of millions of of users publish content, the Web site in order to save these new content, in a very short period of time will be a lot of content updates. In order to display the contents of these updates in real-time, the server will need to directly feed those content to the client's interface when the content is updated. Although it may seem simple, HTTP is unable to properly handle the task. By using the HTTP protocol to detect if there is any content update on the server, you must frequently confirm from the client to the server. If there is no content update on the server, then there is a futile communication. If you want to implement the required functionality on the existing Web. The following HTTP standards become bottlenecks:

• Only one request can be sent on one connection.

• The request can only be initiated from the client and the client cannot receive instructions other than the response.

• The request/response header is sent without compression. The more the first message, the greater the delay.

• Send lengthy headers, each sending the same header each time resulting in more waste

• Data compression format can be selected arbitrarily. Non-forced compression is sent.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/89/B9/wKiom1gaxfXyh29sAABKaqaQO5g305.png "title=" 09-01. PNG "alt=" Wkiom1gaxfxyh29saabkaqaqo5g305.png "/>



How to solve Ajax

Ajax (Asynchronous JavaScript and XML, asynchronous JavaScript and XML technology) is an efficient way to make use of JavaScript and DOM (Document Object model), Asynchronous communication means to replace the load with a partial web page. It is obvious that the data transmitted in the response will be reduced as a result of updating only a subset of the pages compared to the previous synchronous communication. The core technology of Ajax is the API named XMLHttpRequest, which is capable of HTTP communication with the server through a JavaScript scripting language call. By this means, it is possible to initiate a request on a Web page that has been loaded, updating only the local page. The use of Ajax to get content from the server can result in a large number of requests being generated. In addition, Ajax still does not solve the problem of the HTTP protocol itself.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/89/B7/wKioL1gayX7ymubWAABCksm722A844.png "title=" 09-02. PNG "alt=" Wkiol1gayx7ymubwaabcksm722a844.png "/>


Comet's Solution

Once the server-side content has been updated, Comet does not let the request wait, but returns the response directly to the client. This is a function of simulating a server push to the client through a deferred response. Typically, the server receives a request and returns a response as soon as it is processed, but in order to implement push, comet places the response in a pending state and returns the response when there is content updates in the server side. Therefore, once the server side is updated, it can be immediately fed back to the client.

While the content can be updated in real time, the duration of a single connection becomes longer in order to retain the response. Period, additional resources are consumed in order to maintain the connection. In addition, Comet still does not solve the problem of the HTTP protocol itself.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/89/B9/wKiom1gay7nTWC_TAABTUib3Zyc948.png "title=" 09-03. PNG "alt=" Wkiom1gay7ntwc_taabtuib3zyc948.png "/>


Spdy's goal

The advent of improved ease-of-use technologies such as Ajax and comet have improved HTTP to some extent, but the limitations of the HTTP protocol itself are a bit out of the way. In order to make fundamental improvements, there is a need for some agreement-level changes. The SPDY protocol in the ongoing development state is designed to eliminate the bottlenecks encountered by HTTP at the protocol level.


Design and function of 9.2.2 Spdy

Spdy does not completely rewrite the HTTP protocol, but it operates in the form of a new session layer between the application and transport tiers of TCP/IP, and spdy specifies that SSL is used in communications, given security concerns. Spdy is added in the form of a session layer to control the flow of data, but it also uses HTTP to establish a communication connection. As a result, HTTP GET and post methods, cookies, and HTTP messages can be used as usual.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/89/BA/wKiom1ga0UGyzA_lAAAg3Am_xMI303.png "title=" 09-01. PNG "alt=" Wkiom1ga0ugyza_laaag3am_xmi303.png "/>

After using Spdy, the HTTP protocol has the following additional features.

· Multiplexing streams

With a single TCP connection, you can handle multiple HTTP requests without restrictions. Processing of all requests is done on a TCP connection, so the processing efficiency of TCP is improved.

· Give request priority

Spdy not only can handle requests indefinitely, but can also request a priority order by assignment. This is primarily to address the problem of slow response due to low bandwidth when sending multiple requests.

· Compress HTTP Header

Compresses the headers of HTTP requests and responses. In this way, traffic generates less packet traffic and sends fewer bytes.

· Push function

Enables the server to proactively push data to the client. This allows the server to send data directly without waiting for the client's request.

· Server prompt function

The server can proactively prompt the client to request the required resources. Because the resource exists before the client discovers the resource, it is possible to avoid sending unnecessary requests in the event that the resource is cached.


9.2.3 Spdy eliminate the Web bottleneck?

When you want to use Spdy, the Web content side does not have to make any special changes, and Web browsers and Web servers have to make some changes to the corresponding spdy. There are several web browsers that have responded to Spdy's adjustments. In addition, the Web server has also been applied in experimental nature. But importing the technology into the actual web site is not progressing well. Because when Spdy basically only uses the communication multiplexing of a single domain name (IP address), the effect is limited when you use resources from multiple domain names on a Web site. Spdy is indeed a technology that can effectively eliminate HTTP bottlenecks, but many web sites have problems that are not caused by HTTP bottlenecks alone. The speed of the Web site itself, but also from other areas can be carefully studied, such as improving the way Web content is written.



9.3 WebSocket for full-duplex communication using a browser

Using AJAX and Comet technology to communicate can improve the browsing speed of the web. But the problem is that if the communication uses the HTTP protocol, it cannot solve the bottleneck problem completely. WebSocket Network Technology is a new set of protocols and APIs that are implemented to solve these problems. At that time, planning to WebSocket as part of the HTML5 standard, but now he has gradually become an independent standard of agreement. WebSocket communication protocol was set as standard by Rfc-6455-the WebSocket protocol on December 11, 2011.


Design and function of 9.3.1 WebSocket

Websocket, which is the standard for full-duplex communication between a Web browser and a Web server. Among them, the WebSocket protocol is determined by IETF as the standard, the WebSocket API is set as standard by the consortium. The WebSocket technology that is still being developed is designed to solve the problems caused by the flaws that come with XMLHttpRequest in Ajax and Comet.


9.3.2 WebSocket Protocol

Once a communication connection between the Web server and the client is established for the WebSocket protocol, all communications are then dependent on this private protocol. You can send data in any format, such as JSON, XML, HTML, or pictures, to each other during communication. Because it is an HTTP-based protocol, the initiator of the connection is still the client, and once the WebSocket communication connection is established, either the server or the client can send the message directly to the other party. The main features of the WebSocket protocol are as follows:

· Push function

Supports push request functionality that pushes data to clients by the server. This allows the server to send data directly without waiting for the client's request.

· Reduce Traffic Volume

As long as the WebSocket connection is established, you want to remain connected. Compared with HTTP, not only the total cost of each connection is reduced, but also because the WebSocket header information is very small, the traffic is correspondingly reduced. To implement WebSocket communication, you need to complete a "handshake (handshaking)" Step after the HTTP connection is established


    • Handshake • Request

In order to implement websocket communication, it is necessary to use the HTTP Upgrade header field to inform the server that the communication protocol has changed to achieve the purpose of handshake. The Sec-websocket-key field records the necessary key values in the handshake recording process, and the sub-protocol used in the Sec-websocket-protocol field is recorded. Sub-protocols define the names of those connections when they are used separately by the WebSocket protocol standard.

Get/chat http/1.1 Host:server.example.com upgrade:websocket connection:upgrade sec-websocket-key:dgh1i hnhbxbszsbub25jzq== Origin:sec-websocket-protocol:chat, Superchat sec-websocket-version:13
    • Handshake • response

For previous requests, the response of the Status Code 101 switching protocol is returned. The field value of the sec-websocket-accept is generated by the field value of the Sec-websocket-key in the handshake request, and after the successful handshake establishes the WebSocket connection, the communication is not a data frame using HTTP. Instead, WebSocket independent data frames are used.

http/1.1 101 Switching Protocols upgrade:websocket Connection:upgrade Sec-websocket-accept:s3pplmbitxaq9kygzzh zrbjxoo= Sec-websocket-protocol:chat

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/89/B9/wKioL1ga6N6xzRxdAACMPYCTzq0446.png-wh_500x0-wm_3 -wmp_4-s_3029135796.png "title=" 09-02.png "alt=" Wkiol1ga6n6xzrxdaacmpyctzq0446.png-wh_50 "/>

    • WebSocket API

JavaScript can call the "the WebSocket API" (http://www.w3.org/TR/websocket/, developed by the global standards) to provide the WebSocket program interface, in order to achieve WebSocket protocol full-duplex communication. The following is an instance of calling the WebSocket API, sending data once every 50ms.

var socket = new WebSocket (' ws://game.example.com:12010/updates ');                    Socket.onopen = Funtion () {Setintervar (function () {if (Socket.bufferedamount = = 0)            Socket.send (Getupdatedata ());        }, 50); };



9.4 Long-awaited http/2.0

The current mainstream http/1.1 standards have not been revised since the release of RFC2616 in 1999. Spdy and WebSocket technologies have emerged, and it's hard to assert that http/1.1 is still a Web protocol for today. The IETF, which is responsible for Internet technology (Internet Engineering Task Force, Internet Engineering Task Forces), created the Httpbis Working Group with the goal of advancing the next generation of HTTP-----http/2.0 to standardize in November 2014.


Features of http/2.0

The goal of http/2.0 is to improve the user's speed experience when using the Web. Since we are basically going to connect to TCP via http/1.1, now let's explore their implementation based on these protocols.

· SPDY

· HTTP Speed +mobility

· network-friendly HTTP Upgrade


The HTTP speed+ Mobility, drafted by Microsoft Corporation, is a standard for communication speed and performance to improve and improve mobile communications. It is based on the Spdy and websocket that Google has proposed.

network-friendly HTTP upgrade is the standard for improving HTTP performance primarily when communicating on the mobile side.


7 Technology and discussion of http/2.0

HTTP is discussed around the main 7 technologies, and at this stage (August 13, 2012), most tend to adopt the following protocol technologies. However, the discussion is still ongoing, so it is not possible to exclude the possibility of a major change.


Table 9-1:

Compression SPDY, Friendly
Multiplexing SPDY
TLS obligations Speed +mobility
Consultation Speed +mobility, friendly
Client Pull/server push (server push) Speed +mobility
Flow control SPDY
WebSocket Speed +mobility




9.5 Web Server administration files for WebDAV

WebDAV (web-based distributed Authoring and Versioning, Distributed Authoring and versioning based on the World Wide Web) is a distributed file system that allows for direct file copying, editing, and so on for content on a WEB server. It is defined as an extended http/1.1 protocol in RFC4918. In addition to the basic functions of creating and deleting files, he also has the ability to create and manage files, to prevent other user content from being overwritten during file editing, and to modify the file content. Using http/1.1 's Put method and the Delete method, you can create and delete files on the Web server. However, due to safety and convenience, and other considerations, generally not used.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/89/B9/wKioL1ga8d6SeCilAAArUmTFnjA612.png "title=" 09-03. PNG "alt=" Wkiol1ga8d6secilaaarumtfnja612.png "/>


9.5.1 Extended http/1.1 WebDAV

For resources on the server, WebDAV adds some new concepts. Such as

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/89/BC/wKiom1ga846zBLbRAAAYq1Q_ZjI897.png "title=" 09-04. PNG "alt=" Wkiom1ga846zblbraaayq1q_zji897.png "/>

Collection (Collection): a concept that manages multiple resources in a unified way. Various operations are performed in a collection unit. Overlays such as collections of similar collections can also be implemented.

Resource (Resource): The file or collection is called a resource.

Property: Defines the properties of the resource. The definition is executed in the format "name = value"

Lock: Sets the file to a state that cannot be edited. When multiple people are editing at the same time, you can prevent content writing at the same moment.


9.5.2 new methods and status codes in WebDAV

For remote file management, WebDAV adds the following methods to http/1.1 and expands the status code.

Table 9-2 adds the method:

PROPFIND Get Properties
Prooppatch modifying properties
Mkdol Create a Collection
MOVE Mobile Resources
LOCK Resource Plus Lock
UNLOCK Resource Unlocked


Table 9-3 Status codes for extensions

102 Processing Requests are handled normally, but currently in process state
207 Multi-Status
There are multiple states
422 unprocessible Entity Correct format, incorrect content
423 Locked The resource has been locked
424 Failed Dependency Processing a request associated with a request failed, so dependency is no longer maintained
507 Insufficient Storage Insufficient space to save


    • Request instance for WebDAV (below is a request to http://www.example.com/file to initiate a Get property using the PropFind method)

    PROPFIND    /file    HTTP/1.1     host    :    content-type :application/xml;charset= " Utf-8 "    content-length :219        <?xml  version= "1.0"  encoding= "Utf-8"  ?>    <d:propfind xmlns:d= "DAV:" >        <d:prop xmlns:r= "             <R:bigbox/>             <R:author/>             <r:dingaling/>            <r:random /&GT;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&LT;/D:PROP&GT;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&LT;/D: Propfind>
    • WebDAV Response Instance (response to previous PropFind method)

    http/1.1   207 multi-status    content-type  :application/xml;charset= "Utf-8"     Content-Length :831         <?xml version= "1.0"  encoding= "Utf-8"  ?>     <d:multistatus xmlns:d= "DAV" >        <D:response  Xmlns:r= "            <d:href>http:// www.example.com/file </d:href>             <D:propstat>                 <D:prop>                    <R:bigbox>                     <r:boxtype>box type a</r:boxtype>                    <


PS: Why the HTTP protocol audience is so broad

This article explains several protocol use cases that are associated with HTTP. Why can the HTTP protocol audience be so broad? In the past, when new systems or software were written to access the Internet, it was also necessary to write new protocols that corresponded to the necessary functions. Recently, however, most of the systems and software that use HTTP have taken up. There are many reasons for this, and there is a great relationship with the firewall settings of the enterprise or organization. The basic function of a firewall is to prohibit packets that are not specified by protocol and port numbers from passing through, so if you use a new protocol or port number, you must modify the firewall settings.

On the Internet, the most used is the web. The general company will open access to the Web, regardless of whether you have access to FTP or SSH. The web is based on an HTTP protocol, so building a Web server or accessing a Web site is. You need to set firewall http (80/tcp) and HTTPS (443/TCP) permissions beforehand. Many companies or organizations have set permissions to use HTTP as a communications environment, so there is no need to modify firewall settings. Visible HTTP has the big advantage of being simple to import. This is also one of the reasons for the increasing number of HTTP services or content. There are other reasons, such as the fact that the browser as an HTTP client is quite common, the number of HTTP servers is already large, and HTTP itself is an excellent application.


Read "Schematic http" summary--Nineth Chapter

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.