http请求中有多个get请求

时间:2019-01-14 22:54:42

标签: http tcp pipelining

查看客户端与服务器之间的交互以获取图像时,我看到来自客户端的以下HTTP GET请求,其中数据包包含2个HTTP GET请求,并且我不确定服务器将如何响应此类请求?

  1. 服务器将忽略第二个GET请求吗?
  2. 服务器将对每个GET请求一一发送响应吗?
  3. 这似乎不是HTTP管道。请告知是否。

    Transmission Control Protocol, Src Port: 59649 (59649), Dst Port: 8080 (8080), Seq: 1, Ack: 1, Len: 648
        Source Port: 59649
        Destination Port: 8080
        [Stream index: 86]
        [TCP Segment Len: 648]
        Sequence number: 1    (relative sequence number)
        [Next sequence number: 649    (relative sequence number)]
        Acknowledgment number: 1    (relative ack number)
        Header Length: 32 bytes
        Flags: 0x018 (PSH, ACK)
            000. .... .... = Reserved: Not set
            ...0 .... .... = Nonce: Not set
            .... 0... .... = Congestion Window Reduced (CWR): Not set
            .... .0.. .... = ECN-Echo: Not set
            .... ..0. .... = Urgent: Not set
            .... ...1 .... = Acknowledgment: Set
            .... .... 1... = Push: Set
            .... .... .0.. = Reset: Not set
            .... .... ..0. = Syn: Not set
            .... .... ...0 = Fin: Not set
            [TCP Flags: *******AP***]
        Window size value: 683
        [Calculated window size: 43712]
        [Window size scaling factor: 64]
        Checksum:  [validation disabled]
            [Good Checksum: False]
            [Bad Checksum: False]
        Urgent pointer: 0
        Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
            No-Operation (NOP)
                Type: 1
                    0... .... = Copy on fragmentation: No
                    .00. .... = Class: Control (0)
                    ...0 0001 = Number: No-Operation (NOP) (1)
            No-Operation (NOP)
                Type: 1
                    0... .... = Copy on fragmentation: No
                    .00. .... = Class: Control (0)
                    ...0 0001 = Number: No-Operation (NOP) (1)
            Timestamps: TSval 6345, TSecr 6344
                Kind: Time Stamp Option (8)
                Length: 10
                Timestamp value: 6345
                Timestamp echo reply: 6344
        [SEQ/ACK analysis]
            [iRTT: 0.000099000 seconds]
            [Bytes in flight: 648]
    
    Hypertext Transfer Protocol
        GET  HTTP/1.1\r\n
            [Expert Info (Chat/Sequence): GET  HTTP/1.1\r\n]
                [GET  HTTP/1.1\r\n]
                [Severity level: Chat]
                [Group: Sequence]enter code here
            Request Method: GET
            Request URI: 
            Request Version: HTTP/1.1
        Host: \r\n
        sent: \r\n
        User-Agent: \r\n
        Accept-Encoding: gzip, deflate\r\n
        Accept-Language: en-GB,*\r\n
        Connection: keep-alive\r\n
        \r\n
        [Full request URI: ]
        [HTTP request 2/2]
        [Prev request in frame: 1254]
        [Response in frame: 1272]
    
    Hypertext Transfer Protocol
        GET \r\n
            [Expert Info (Chat/Sequence): GET  HTTP/1.1\r\n]
                [GET  HTTP/1.1\r\n]
                [Severity level: Chat]
                [Group: Sequence]
            Request Method: GET
            Request URI: 
            Request Version: HTTP/1.1
        Host: \r\n
        sent: \r\n
        User-Agent: \r\n
        Accept-Encoding: gzip, deflate\r\n
        Accept-Language: en-GB,*\r\n
        Connection: keep-alive\r\n
        \r\n
        [Full request URI: ]
        [HTTP request 2/2]
        [Prev request in frame: 1254]
        [Response in frame: 1272]
    

我可以使用任何在线工具来测试此类请求吗?

1 个答案:

答案 0 :(得分:1)

将多个HTTP请求放在一个TCP数据包中(如果它们适合)是完全可以接受的。

您所看到的实际上是 HTTP管道,这在HTTP 1.1规范的RFC 2616 Section 8RFC 7230 Section 6.3.2中都有介绍。客户端正在发送新的GET请求,而无需先等待对先前GET请求的响应。那就是流水线的定义:

  

HTTP请求和响应可以在连接上通过管道传递。 流水线允许客户端在不等待每个响应的情况下发出多个请求,从而可以更高效地使用单个TCP连接,而花费的时间却少得多。

TCP只是通过对两个HTTP请求使用单个TCP数据包来优化事情。客户端可能启用了send coalescing(又名“ Nagle算法”)(默认情况下,大多数套接字库都启用了该功能)以减少网络流量。

为了使服务器响应流水线请求,必须使用持久连接,这是流水线的另一个要求,并且在您的示例中清晰可见(Connection: keep-alive请求标头)。

TCP是一个字节流,较低级别的TCP框架与较高级别的协议层无关。编写正确的 HTTP接收器将能够分离单个HTTP消息,而与所使用的TCP框架无关,并根据需要对其进行单独处理。 HTTP 1.1规范要求所有请求均按照接收到的顺序进行响应(HTTP 2.0对此进行了更改,但这是处理过程中涉及更多的过程-复用-我将不赘述)。

因此,回答您的问题:

  1. 服务器将忽略第二个GET请求吗?-否

  2. 服务器将对每个GET请求一一发送响应吗?-是

  3. 这似乎不是HTTP流水线。请告知是否。-是,但并非出于您的考虑。