duanji2002 2018-05-20 11:16
浏览 358

http2实现中的PRI方法导致问题

I am trying to extend a server with HTTP/2 which already supports HTTP/1.1 with TLS v1.2. I am writing it in Go where I define tls config like this -

tlsConfig := &tls.Config{
                    Certificates: []tls.Certificate{cert},
                    ServerName:   "mysrvr",
                    NextProtos:   []string{"h2", "http/1.1", "http/1.0"},
                    Time:         time.Now,
                    Rand:         rand.Reader,
            }

As is evident, I have used "h2" string to set up ALPN handshake.

Now when I make request via curl, I receive this request -

$ curl -v https://127.0.0.1:8000 -k --http2

When I parse request, it shows a PRI method being sent first instead of GET -

HTTP/2.0
PRI

I got some idea on PRI method from https://tools.ietf.org/html/rfc7540#page-78 wherein it says the following -

This method is never used by an actual client.
This method will appear to be used when an HTTP/1.1 server or
intermediary attempts to parse an HTTP/2 connection preface. 

My question now is why was PRI request sent, when clearly the server supports HTTP/2? Do I need to parse it and respond with empty SETTINGS frame in accordance with HTTP/2 spec or should the Go http2 runtime should have taken care of it?

I am using http.ReadRequest to parse client requests, but that doesn't seem to be working for HTTP/2 requests even when I ignore PRI requests (as suggested below).

  • 写回答

1条回答 默认 最新

  • duanpo1821 2018-05-20 13:12
    关注

    The first message a HTTP/2 client should send is this PRI message. From the HTTP/2 specification:

    In HTTP/2, each endpoint is required to send a connection preface as a final confirmation of the protocol in use and to establish the initial settings for the HTTP/2 connection. The client and server each send a different connection preface.

    The client connection preface starts with a sequence of 24 octets, which in hex notation is:

    0x505249202a20485454502f322e300d0a0d0a534d0d0a0d0a
    

    That is, the connection preface starts with the string PRI * HTTP/2.0 SM ). This sequence MUST be followed by a SETTINGS frame (Section 6.5), which MAY be empty.

    ...

    Note: The client connection preface is selected so that a large proportion of HTTP/1.1 or HTTP/1.0 servers and intermediaries do not attempt to process further frames.

    The point of this message is that it is a fake HTTP/1-like message so any server which is not HTTP/2 aware should response with an error.

    Any HTTP/2 server should expect this message to be sent, and then should just ignore it, and the carry on speaking HTTP/2.

    In fact if this message is NOT sent, then the server should treat this as an error and not continue:

    Clients and servers MUST treat an invalid connection preface as a connection error (Section 5.4.1) of type PROTOCOL_ERROR. A GOAWAY frame (Section 6.8) MAY be omitted in this case, since an invalid preface indicates that the peer is not using HTTP/2.

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP