简体   繁体   English

HTTP代理检测HTTP客户端断开连接

[英]HTTP proxy detecting HTTP client disconnection

I'm new to HTTP, and developing an applicative proxy. 我是HTTP的新手,正在开发一个应用代理。 I want to avoid defining timeouts for operations, and instead rely on the the client to close the connection. 我想避免为操作定义超时,而是依靠客户端关闭连接。 I'm wondering if this is possible? 我想知道这是否可能?

here's a very dumbed down pseudo code 这是一个非常愚蠢的伪代码

void handle_request(Request http_request, Response http_response)
{
   string modified_request = parse(http_request);
   response_from_server = remote_server->send_request(modified_request);
   while(true) {
     if(response_from_server ->wait_for_data(1000 /* milliseconds */)) {
       http_response->write_data(response_from_server->read_data());
       continue;
     }

     if(!http_response.check_if_the_client_connection_to_me_is_still_active()) // how to do this?
         return;
     }
   }
}

another way to ask this is: 另一种询问方式是:

  1. in an HTTP proxy, can I use the timeouts from the remote cilent and the remote server without adding yet another timeout? 在HTTP代理中,我可以在不添加其他超时的情况下使用来自远程客户端和远程服务器的超时吗?
  2. how do I detect that either the remote server or remote client have timed-out? 如何检测到远程服务器或远程客户端超时?

incidentally, I'm developing in C++ using Poco. 顺便说一句,我正在使用Poco在C ++中进行开发。

You cannot write a serious TCP application without using timeouts. 如果不使用超时, 就无法编写严肃的TCP应用程序。 They are in some cases the only way you can detect a dropped connection while reading. 在某些情况下,它们是您在读取时检测到断开连接的唯一方法。 TCP provides the following ways to detect a dropped connection: TCP提供了以下方法来检测断开的连接:

  1. The various EOS conditions on read. 读取各种EOS条件。
  2. 'Connection reset' on write or occasionally read. 写或偶尔读时“连接重置”。
  3. Read timeout. 读取超时。

That's it. 而已。 There aren't any more. 没有了。

You should also enable TCP keepalive from your end, but that only kicks in after two hours. 您还应该从一开始就启用TCP keepalive,但这仅在两个小时后生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM