强制 Http 1.0 idHttpServer 和 TIME_WAIT

发布于 2024-10-18 15:09:31 字数 963 浏览 5 评论 0原文

Delphi 2010,来自 Svn 的 Last Indy 源代码。

有谁知道如何强制 TIDHttpServer 发送 http 1.0 响应,而不是发送 http 1.1? 我想摆脱持久连接(保持活动),并且我希望客户端与我的服务器断开连接,而不是我的服务器与客户端断开连接(以避免服务器中的 TIME_WAIT)。

一些数据:

客户端(在本例中为 Internet Explorer)发出的请求:

GET / HTTP/1.0
接受:/
接受语言:pt-BR
用户代理:Mozilla/4.0(兼容;MSIE 8.0;Windows NT 6.1;WOW64;Trident/4.0;SLCC2;.NET CLR 2.0.50727;.NET CLR 3.5.30729;.NET CLR 3.0.30729;Media Center PC 6.0 .NET4.0E)
主机:本地主机:114
连接:保持活动

来自我的 Indy 服务器的响应:

HTTP/1.1 200 OK
连接:关闭
内容类型:text/html;字符集=ISO-8859-1
Content-Length: 2717

正如你所看到的,客户端明确告诉服务器使用http 1.0,但indy服务器响应是http 1.1。

编辑:

我发现最好的解决方案是在 OnCommandGet 事件中设置:

AResponseInfo.CloseConnection := False;
AResponseInfo.Connection := '关闭';

AResponseInfo.CloseConnection := False 使服务器不与客户端断开连接,而 Connection := 'close' 使客户端与服务器断开连接,避免服务器 TIME_WAIT。

Delphi 2010, Last Indy source code from Svn.

Does anyone knows how can I force TIDHttpServer to send a http 1.0 response, instead of sending http 1.1?
I want to get rid of persistent connections (keep-alive) and also i want the client to disconnect from my server and not my server disconnect from client (to avoid TIME_WAIT in my server).

Some Data:

Request made by a client (in this case, Internet Explorer):

GET / HTTP/1.0
Accept: /
Accept-Language: pt-BR
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
Host: localhost:114
Connection: Keep-Alive

Response from my Indy Server:

HTTP/1.1 200 OK
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 2717

As you can see, the client explicity told the server to use http 1.0, but the indy server response was http 1.1.

EDIT:

I figured out that the best solution is to set in the OnCommandGet event:

AResponseInfo.CloseConnection := False;
AResponseInfo.Connection := 'close';

AResponseInfo.CloseConnection := False makes the server do not disconnect from the client and Connection := 'close' makes the client disconnect from the server avoiding servers TIME_WAIT.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身狗的梦 2024-10-25 15:09:31

在 IdCustomHTTPServer.pas 中,

版本字符串“HTTP/1.1”硬编码在 TIdHTTPResponseInfo.WriteHeader 方法中。

此类没有可以覆盖的工厂,因此您可以使用后代版本更改其行为。它是在 TIdCustomHTTPServer.DoExecute 中显式创建的。

但是,由于您确实拥有源代码,因此您可以将硬编码字符串更改为“HTTP/1.0”或更改其行为以根据属性设置进行响应。

另外,设置 IdHttpServer.KeepLive := False; 会停止持久会话,但它确实会导致服务器在请求结束时断开与客户端的连接。

In IdCustomHTTPServer.pas

The version string 'HTTP/1.1' is hard coded in the TIdHTTPResponseInfo.WriteHeader method.

This class does not have factory that you can override so you can change it's behavior with a descendant version. It's explicitly created in TIdCustomHTTPServer.DoExecute

However, since you do have the source you could change the hard coded string to 'HTTP/1.0' or change it's behavior to respond based on a property setting.

Also setting IdHttpServer.KeepLive := False; would stop the persistent sessions but it does cause the server to disconnect the client at the end of the request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文