HTTP管线请求文本范例 [英] HTTP pipelining request text example
问题描述
下面是一个例子HTTP 1.1的呼叫请求与单页:
Below is an example HTTP 1.1 call with a single page requested :
GET /jq.js HTTP/1.1
Host: 127.0.0.1
Accept: */*
我 HTTP流水线了解,多个请求可以在不中断连接发送。
I understand with HTTP Pipelining, multiple requests can be sent without breaking the connection.
推荐答案
8.1.2.2流水线
8.1.2.2 Pipelining
这支持持久连接的客户端的可以管道的要求(即发送多个请求,而无需等待每个响应)。服务器必须发送其响应的相同顺序已收到请求这些请求。
A client that supports persistent connections MAY "pipeline" its requests (i.e., send multiple requests without waiting for each response). A server MUST send its responses to those requests in the same order that the requests were received.
该连接建立后,立即采取持久连接和管道客户的应该是ppared如果第一个流水线尝试失败重新尝试他们的连接$ P $。如果客户端这样的重试,它的 MUST NOT 管道才知道连接是持久的。客户端必须也ppared重新发送他们的请求$ P $如果服务器关闭发送所有相应的响应前的连接。
Clients which assume persistent connections and pipeline immediately after connection establishment SHOULD be prepared to retry their connection if the first pipelined attempt fails. If a client does such a retry, it MUST NOT pipeline before it knows the connection is persistent. Clients MUST also be prepared to resend their requests if the server closes the connection before sending all of the corresponding responses.
客户端不应使用非幂等方法或几种方法非幂等序列(参见9.1.2)管道请求。否则,传输连接的premature终止可能导致不确定的结果。希望发送一个非幂等请求的客户端的应该等待发送请求,直到它已经收到了previous请求的响应状态。
Clients SHOULD NOT pipeline requests using non-idempotent methods or non-idempotent sequences of methods (see section 9.1.2). Otherwise, a premature termination of the transport connection could lead to indeterminate results. A client wishing to send a non-idempotent request SHOULD wait to send that request until it has received the response status for the previous request.
所以,首先事实是,你应该在保持连接状态。所以,你的应添加连接:保持活动
关键字在你的请求头,但一些网络服务器可能仍然接受pipeling没有这个保活状态。另一方面,这可能被服务器拒绝,服务器可以或可以不接受在存活模式的连接。所以,在任何时间,正在或的keepalived没有,你可以发送请求3在一个连接流水线,并获得唯一的一个响应。
So, first fact is that you should be in a KeepAlive status. So you should add Connection: keep-alive
keyword in your request headers, but some webservers may still accept pipeling without this keep alive status. On the other hand, this could be rejected by the server, the server may or may not accept your connection in keepalive mode. So, at any time, being in keepalived or not, you may send 3 requests pipelined in one connection, and get only one response.
精神,我们可以找到一个很好的方式通过telnet来测试它。
From this gist we can find a nice way to test it with telnet.
问计存活与连接:保持活动
标题:
(echo -en "GET /index.html HTTP/1.1\nHost: foo.com\nConnection: keep-alive\n\nGET /index.html HTTP/1.1\nHost: foo.com\n\n"; sleep 10) | telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.lan.
Escape character is '^]'.
HTTP/1.1 200 OK
Date: Sun, 27 Oct 2013 17:51:58 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Sun, 04 Mar 2012 15:00:29 GMT
ETag: "56176e-3e-4ba6c121c4761"
Accept-Ranges: bytes
Content-Length: 62
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=100 <======= Keepalive!
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
<html>
<body>
<h1>test</h1>
</body>
</html>
HTTP/1.1 200 OK
Date: Sun, 27 Oct 2013 17:51:58 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Sun, 04 Mar 2012 15:00:29 GMT
ETag: "56176e-3e-4ba6c121c4761"
Accept-Ranges: bytes
Content-Length: 62
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
<html>
<body>
<h1>test</h1>
</body>
</html>
它的工作原理。
不要求存活:
(echo -en "GET /index.html HTTP/1.1\nHost: foo.com\nConnection: keep-alive\n\nGET /index.html HTTP/1.1\nHost: foo.com\n\n"; sleep 10) | telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.lan.
Escape character is '^]'.
HTTP/1.1 200 OK
Date: Sun, 27 Oct 2013 17:49:37 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Sun, 04 Mar 2012 15:00:29 GMT
ETag: "56176e-3e-4ba6c121c4761"
Accept-Ranges: bytes
Content-Length: 62
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
<html>
<body>
<h1>test</h1>
</body>
</html>
HTTP/1.1 200 OK
Date: Sun, 27 Oct 2013 17:49:37 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Sun, 04 Mar 2012 15:00:29 GMT
ETag: "56176e-3e-4ba6c121c4761"
Accept-Ranges: bytes
Content-Length: 62
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
<html>
<body>
<h1>test</h1>
</body>
</html>
Connection closed by foreign host.
它也可以,我没有要求它,但它看起来像一个存活的答案(5秒后,关闭它是Apache的设定值)。和流水线的答案,我让我的两个页面。
It also works, I did not ask for it but it looks like a Keepalive answer (closing after 5s which is the value set in Apache). And a pipelined answer, I get my two pages.
现在,如果我通过设置在Apache中的任何存活的连接prevent用法:
Now if I prevent usage of any Keepalive connection in Apache by setting:
Keepalive Off
和重新启动它:
(echo -en "GET /index.html HTTP/1.1\nHost: foo.com\nConnection: keep-alive\n\nGET /index.html HTTP/1.1\nHost: foo.com\n\n"; sleep 10) | telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.lan.
Escape character is '^]'.
HTTP/1.1 200 OK
Date: Sun, 27 Oct 2013 18:02:41 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Sun, 04 Mar 2012 15:00:29 GMT
ETag: "56176e-3e-4ba6c121c4761"
Accept-Ranges: bytes
Content-Length: 62
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=utf-8
<html>
<body>
<h1>test</h1>
</body>
</html>
Connection closed by foreign host.
答案只有一个......所以,服务器可以拒绝我的流水线请求。
Only one answer... So the server can reject my request for pipelining.
现在,对服务器和浏览器的支持,我觉得你的维基百科人士告诉就够了: - )
Now, for support on servers and browsers, I think your wikipedia source tells enough :-)
这篇关于HTTP管线请求文本范例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!