本文介绍了HTTP1.1到HTTP/2:标头呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTTP 1.1中,状态行为

In HTTP 1.1, the status line was

scheme/version code reason
HTTP/1.1 200 OK

我在HPACK规范中看到了:scheme和:status标头.但是,我没有看到任何版本或原因?没有一个吗?

I see :scheme and :status headers in the HPACK spec. I don't however see anything for version or reason? Is there not one?

在HTTP 1.1中的请求中,请求行为

In a request in HTTP 1.1, the request line was

method uri scheme/version
POST http://myhost.com HTTP/1.1

我看到:method和我看到:path,我认为这只是一个相对路径,与完整的绝对路径不同(并且由于Chrome和Firefox将HTTPS推送至HTTP/2,所以这可能很有意义).我没有看到版本标头.

I see :method and I see :path, which I think is just a relative path, which is not the same as the full absolute path (and since Chrome and Firefox are pushing HTTPS for HTTP/2, this may make sense). I do not see version header though.

有版本标头吗?还是在协议决定之前就已经知道了这一点,所以实际上并不需要它?

Is there a version header? Or is it seen that this will always be known before the protocol decision such that it is not really needed?

原因码呢?是否假定这些参数是恒定的,以便消失(我在这里猜)?

What about reason codes? Is it assumed these are pretty constant so that goes away (I am guessing here)?

推荐答案

在HTTP/1中,需要版本令牌来区分HTTP/1.0和HTTP/1.1,因为它们具有相同的线路表示形式,但支持不同的功能.

In HTTP/1, the version token was needed to differentiate HTTP/1.0 from HTTP/1.1, since they had the same wire representation, but were supporting different features.

例如,客户端声明HTTP/1.1隐式告知服务器它支持持久连接和内容组块.

For example, a client declaring HTTP/1.1 implicitly tells the server that it supports persistent connections and content chunking.

使用HTTP/2,协议版本已通过协商.

With HTTP/2, the protocol version is negotiated.

在明文HTTP/2中,Upgrade标头报告h2c,其中2表示协议的版本2.我想对于HTTP/3,令牌将更改为h3c.对于加密的HTTP/2也会发生类似的情况,其中令牌h2是通过ALPN协商的.

In clear-text HTTP/2, the Upgrade header reports h2c, where the 2 means version 2 of the protocol. I imagine that for HTTP/3 the token will change to h3c.Similarly happens for encrypted HTTP/2 where the token h2 is negotiated via ALPN.

原因消息已被删除为冗余消息,因为状态代码已经在传达所有必要的信息(更不用说它们可能是攻击媒介).

Reason messages have been dropped as being redundant, as the status code was already conveying all the necessary information (not to mention that they could be attack vectors).

由于这些原因,HTTP/2既没有版本也没有原因伪头.

For these reasons, HTTP/2 does not have neither version nor reason pseudo-headers.

这篇关于HTTP1.1到HTTP/2:标头呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:04