HTTP20中文版.docx

上传人:b****8 文档编号:10478930 上传时间:2023-02-13 格式:DOCX 页数:129 大小:153.72KB
下载 相关 举报
HTTP20中文版.docx_第1页
第1页 / 共129页
HTTP20中文版.docx_第2页
第2页 / 共129页
HTTP20中文版.docx_第3页
第3页 / 共129页
HTTP20中文版.docx_第4页
第4页 / 共129页
HTTP20中文版.docx_第5页
第5页 / 共129页
点击查看更多>>
下载资源
资源描述

HTTP20中文版.docx

《HTTP20中文版.docx》由会员分享,可在线阅读,更多相关《HTTP20中文版.docx(129页珍藏版)》请在冰豆网上搜索。

HTTP20中文版.docx

HTTP20中文版

HTTP全称为HyperTextTransferProtocol,中文叫做超文本传输协议。

用于Web 应用层传输,是Web架构的核心,它至今公布有3个版本:

∙HTTP0.9,只有基本的文本GET功能。

∙HTTP1.0,完善的请求/响应模型,并将协议补充完整。

∙HTTP1.1,在1.0基础上进行更新,增加了如长久连接keep-alive与chunked等功能。

距最近1999年6月 HTTP1.1RFC2616 发布以来至今已有15年。

而HTTP2.0首个draft已于2012年11月发布,预计到明年初正式发布。

它保证了与HTTP1.1的完全语义兼容,最初考虑的是GoogleSPDY协议、微软的SM协议和Network-FriendlyHTTP更新。

最终各方推荐了SPDY协议,并在此基础上进行了相应更新。

HTTP2.0相比1.1的更新大部分集中于:

∙多路复用

∙HEAD压缩

∙服务器推送

∙优先级请求

作为与时俱进的我们,有必要去了解和学习HTTP2.0,它对我们未来Web性能优化工作起到很重要的作用,是一切优化的基础。

现Chrome里也已使用SPDY。

今天我们很高兴和大家分享一则信息,由FEX的zhangtao等同学们,业余花费近半年时间翻译的HTTP2.0草案发布。

via HTML5中国

附上zhangtao的 Github原文:

IETFHTTP2草案(draft-ietf-httpbis-http2-13)

摘要

本规范描述了一种优化的超文本传输协议(HTTP)。

HTTP/2通过引进报头字段压缩以及多路复用来更有效利用网络资源、减少感知延迟。

另外还介绍了服务器推送规范。

本文档保持对HTTP/1.1的后向兼容,HTTP的现有的语义保持不变。

1介绍

TheHypertextTransferProtocol(HTTP)isawildlysuccessfulprotocol.However,theHTTP/1.1messageformat([RFC7230],Section3)wasdesignedtobeimplementedwiththetoolsathandinthe1990s,notmodernWebapplicationperformance.Assuchithasseveralcharacteristicsthathaveanegativeoveralleffectonapplicationperformancetoday.

超文本传输协议(HTTP)是一个非常成功的协议。

但是HTTP/1.1是针对90年代的情况而不是现代web应用的性能而设计的,导致它的一些特点已经对现代应用程序的性能产生负面影响。

Inparticular,HTTP/1.0onlyallowsonerequesttobeoutstandingatatimeonagivenconnection.HTTP/1.1pipeliningonlypartiallyaddressedrequestconcurrencyandsuffersfromhead-of-lineblocking.Therefore,clientsthatneedtomakemanyrequeststypicallyusemultipleconnectionstoaserverinordertoreducelatency.

特别是,HTTP/1.0只允许在一个连接上建立一个当前未完成的请求。

HTTP/1.1管道只部分处理了请求并发和报头阻塞的问题。

因此客户端需要发起多次请求通过数次连接服务器来减少延迟。

Furthermore,HTTP/1.1headerfieldsareoftenrepetitiveandverbose,which,inadditiontogeneratingmoreorlargernetworkpackets,cancausethesmallinitialTCP[TCP]congestionwindowtoquicklyfill.ThiscanresultinexcessivelatencywhenmultiplerequestsaremadeonasinglenewTCPconnection.

此外,HTTP/1.1的报头字段经常重复和冗长。

在产生更多或更大的网络数据包时,可能导致小的初始TCP堵塞窗口被快速填充。

这可能在多个请求建立在一个新的TCP连接时导致过度的延迟。

ThisspecificationaddressestheseissuesbydefininganoptimizedmappingofHTTP'ssemanticstoanunderlyingconnection.Specifically,itallowsinterleavingofrequestandresponsemessagesonthesameconnectionandusesanefficientcodingforHTTPheaderfields.Italsoallowsprioritizationofrequests,lettingmoreimportantrequestscompletemorequickly,furtherimprovingperformance.

本协议通过定义一个优化的基础连接的HTTP语义映射来解决这些问题。

具体地,它允许在同一连接上交错地建立请求和响应消息,并使用高效率编码的HTTP报头字段。

它还允许请求的优先级,让更多的重要的请求更快速的完成,进一步提升了性能。

Theresultingprotocolisdesignedtobemorefriendlytothenetwork,becausefewerTCPconnectionscanbeusedincomparisontoHTTP/1.x.Thismeanslesscompetitionwithotherflows,andlonger-livedconnections,whichinturnleadstobetterutilizationofavailablenetworkcapacity.

最终协议设计为对网络更友好,因为它相对HTTP/1.x减少了TCP连接。

这意味着与其他流更少的竞争以及更长时间的连接,从而更有效地利用可用的网络容量。

Finally,thisencapsulationalsoenablesmoreefficientprocessingofmessagesthroughuseofbinarymessageframing.

最后,这种封装也通过使用二进制消息帧使信息处理更具扩展性。

2HTTP/2协议概述

HTTP/2providesanoptimizedtransportforHTTPsemantics.HTTP/2supportsallofthecorefeaturesofHTTP/1.1,butaimstobemoreefficientinseveralways.

HTTP/2提供了HTTP语义的传输优化。

HTTP/2支持所有HTTP/1.1的核心特征,并且在不同的方面做的更高效。

ThebasicprotocolunitinHTTP/2isaframe(Section4.1).Eachframetypeservesadifferentpurpose.Forexample,HEADERSandDATAframesformthebasisofHTTPrequestsandresponses(Section8.1);otherframetypeslikeSETTINGS,WINDOW_UPDATE,andPUSH_PROMISEareusedinsupportofotherHTTP/2features.

HTTP/2中基本的协议单位是帧。

每个帧都有不同的类型和用途。

例如,报头(HEADERS)和数据(DATA)帧组成了基本的HTTP请求和响应;其他帧例如设置(SETTINGS),窗口更新(WINDOW_UPDATE),和推送承诺(PUSH_PROMISE)是用来实现HTTP/2的其他功能。

MultiplexingofrequestsisachievedbyhavingeachHTTPrequest-responseexchangedassignedtoasinglestream(Section5).Streamsarelargelyindependentofeachother,soablockedorstalledrequestdoesnotpreventprogressonotherrequests.

请求多路复用是通过在一个流上分配多个HTTP请求响应交换来实现的(章节5)。

流在很大程度上是相互独立的,因此一个请求上的阻塞或终止并不会影响其他请求的处理。

Flowcontrolandprioritizationensurethatitispossibletoproperlyusemultiplexedstreams.Flowcontrol(Section5.2)helpstoensurethatonlydatathatcanbeusedbyareceiveristransmitted.Prioritization(Section5.3)ensuresthatlimitedresourcescanbedirectedtothemostimportantrequestsfirst.

流量控制和优先级能确保正确使用复用流。

流量控制(章节5.2)有助于确保只传播接受者需要使用的数据数据。

优先级(章节5.3)能确保有限的资源能优先被重要的请求使用。

HTTP/2addsanewinteractionmode,wherebyaservercanpushresponsestoaclient(Section8.2).Serverpushallowsaservertospeculativelysendaclientdatathattheserveranticipatestheclientwillneed,tradingoffsomenetworkusageagainstapotentiallatencygain.Theserverdoesthisbysynthesizingarequest,whichitsendsasaPUSH_PROMISEframe.Theserveristhenabletosendaresponsetothesyntheticrequestonaseparatestream.

HTTP/2添加了一种新的交互模式,即服务器能推送消息给客户端。

服务器推送允许服务端预测客户端需要来发送数据给客户端,交换网络的使用来阻止潜在的延迟增长。

服务器通过复用一个以PUSH_PROMISE帧发送的请求来实现推送,然后服务端可以在一个单独的流里面发送响应给这个合成的请求。

FramesthatcontainHTTPheaderfieldsarecompressed(Section4.3).HTTPrequestscanbehighlyredundant,socompressioncanreducethesizeofrequestsandresponsessignificantly.

帧包含的HTTP报头字段是压缩的。

HTTP请求有可能是高度冗余的,因此压缩能显著减少请求和响应的大小。

文档结构

TheHTTP/2specificationissplitintofourparts:

HTTP/2协议被分为以下四个部分:

∙StartingHTTP/2(Section3)covershowanHTTP/2connectionisinitiated.

∙Theframing(Section4)andstreams(Section5)layersdescribethewayHTTP/2framesarestructuredandformedintomultiplexedstreams.

∙Frame(Section6)anderror(Section7)definitionsincludedetailsoftheframeanderrortypesusedinHTTP/2.

∙HTTPmappings(Section8)andadditionalrequirements(Section9)describehowHTTPsemanticsareexpressedusingframesandstreams.

∙启动HTTP/2(章节3)包含了一个HTTP/2连接是如何初始化的。

∙帧(章节4)和流层(章节5)描述了HTTP/2流的结构以及如何形成复用流的。

∙帧(章节6)和错误码(章节7)定义了HTTP/2中使用的流和错误类型的详细内容。

∙HTTP寻址(章节8)和拓展需求(章节9)描述了HTTP语义化是如何由帧和流表达的。

WhilesomeoftheframeandstreamlayerconceptsareisolatedfromHTTP,theintentisnottodefineacompletelygenericframinglayer.TheframingandstreamslayersaretailoredtotheneedsoftheHTTPprotocolandserverpush.

一些帧和流层的概念是与HTTP隔离的,因为意图并不是定义一个完全通用的帧层。

这些帧和流层是为了HTTP协议和服务端推送的需求定制的。

约定和术语

Thekeywords"MUST","MUSTNOT","REQUIRED","SHALL","SHALLNOT","SHOULD","SHOULDNOT","RECOMMENDED","MAY",and"OPTIONAL"inthisdocumentaretobeinterpretedasdescribedinRFC2119[RFC2119].

文档中出现的关键字“必须”,“绝对不能”,“要求”,“应”,“不应”,“应该”,“不应该”,“建议”,“可以”及“可选”可通过在RFC2119的解释进行理解【RFC2119】

Allnumericvaluesareinnetworkbyteorder.Valuesareunsignedunlessotherwiseindicated.Literalvaluesareprovidedindecimalorhexadecimalasappropriate.Hexadecimalliteralsareprefixedwith0xtodistinguishthemfromdecimalliterals.

所有的数值都是按网络字节顺序。

除非有另外说明,数值是无符号的。

按情况提供十进制或十六进制的文本值。

十六进制用前缀0x来区分。

Thefollowingtermsareused:

∙client:

TheendpointinitiatingtheHTTP/2connection.connection:

Atransport-levelconnectionbetweentwoendpoints.

∙connectionerror:

AnerrorthataffectstheentireHTTP/2connection.

∙endpoint:

Eithertheclientorserveroftheconnection.

∙frame:

ThesmallestunitofcommunicationwithinanHTTP/2connection,consistingofaheaderandavariable-lengthsequenceofbytesstructuredaccordingtotheframetype.

∙peer:

Anendpoint.Whendiscussingaparticularendpoint,"peer"referstotheendpointthatisremotetotheprimarysubjectofdiscussion.

∙receiver:

Anendpointthatisreceivingframes.

∙sender:

Anendpointthatistransmittingframes.

∙server:

TheendpointwhichdidnotinitiatetheHTTP/2connection.

∙stream:

Abi-directionalflowofframesacrossavirtualchannelwithintheHTTP/2connection.

∙streamerror:

AnerrorontheindividualHTTP/2stream.

文中术语包括:

∙客户端:

发起HTTP/2请求的端点

∙连接:

在两个端点之间的传输层级别的连接

∙连接错误:

整个HTTP/2连接过程中发生的错误

∙端点:

连接的客户端或服务器

∙帧:

HTTP/2.0通信连接中的最小单元,包括根据帧类型结构的字节的报头和可变长度的序列

∙对等端:

一个端点。

当讨论特定的端点时,“对等端”指的是讨论的主题的远程端点

∙接收端:

正在接收帧的端点

∙发送端:

正在传输帧的端点

∙服务端:

不是启动HTTP/2连接的端点

∙流:

一个双向字节帧流穿过HTTP/2连接中的虚拟通道

∙流错误:

一个HTTP/2流中的错误

3启动HTTP/2

AnHTTP/2connectionisanapplicationlevelprotocolrunningontopofaTCPconnection([TCP]).TheclientistheTCPconnectioninitiator.

一个HTTP/2连接是运行在TCP连接上的应用层协议。

客户端是TCP连接的发起者。

HTTP/2usesthesame"http"and"https"URIschemesusedbyHTTP/1.1.HTTP/2sharesthesamedefaultportnumbers:

80for"http"URIsand443for"https"URIs.Asaresult,implementationsprocessingrequestsfortargetresourceURIslike http:

//example.org/foo or requiredtofirstdiscoverwhethertheupstreamserver(theimmediatepeertowhichtheclientwishestoestablishaconnection)supportsHTTP/2.

HTTP/2使用与HTTP/1.1相同的"http"和"https"资源标识符(URI)。

使用相同的默认端口:

"http"的80端口及“https”的443端口。

因此,实现对例如http:

//example.org/foo或

ThemeansbywhichsupportforHTTP/2isdeterminedisdifferentfor"http"and"https"URIs.Discoveryfor"http"URIsisdescribedinSection3.2.Discoveryfor"https"URIsisdescribedinSection3.3.

这意味着检测“http”及“https”的URIs是否支持HTTP/2的方法是不一样的。

检测"http"URIs在章节3.2中描述。

检测"https"URIs在章节3.3中描述。

3.1HTTP/2版本定义

Theprotocoldefinedinthisdocumenthastwoidentifiers.

∙Thestring"h2"identifiestheprotocolwhereHTTP/2usesTLS[TLS12].ThisidentifierisusedintheTLSapplicationlayerprotocolnegotiationextension(ALPN)[TLSALPN]fieldandanyplacethatHTTP/2overTLSisidentified.

The"h2"stringisserializedintoanALPNprotocolidentifierasthetwooctetsequence:

0x68,0x32.

∙Thestring"h2c"identifiestheprotocolwhereHTTP/2isrunovercleartextTCP.ThisidentifierisusedintheHTTP/1.1Upgradeheaderfieldandanypl

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 管理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1