如何在Google Chrome中正确响应HTTP CONNECT

时间:2014-07-09 14:24:22

标签: google-chrome https proxy-server

我正在构建代理服务器,在收到HTTP CONNECT请求后,我建立了与目标服务器的连接,如果成功返回

HTTP/1.1 200 Connection established
<<empty line>>

在Firefox中,这会导致隧道的打开和数据交换,加载并最终在浏览器中传送/呈现

在谷歌浏览器中,我立即看到:

ERR_TUNNEL_CONNECTION_FAILED

由于服务器似乎适用于Firefox而不适用于Chrome,因此我只能假设Chrome需要不同的响应。有谁知道我在这里做错了什么?

修改

我在这里发现this铬问题描述了相同的症状 - 用户获取ERR_TUNNEL_CONNECTION_FAILED。我启用了--log-net-log命令行参数,并且可以在日志中看到在收到我的200连接建立的代理响应后直接发生ERR_TUNNEL_CONNECTION_FAILED错误。

请求和响应之间的较高值我看到-109错误,对应于ADDRESS_UNREACHABLE。

我在下面提到了我认为网络日志的相关部分是:

{"params":{"headers":["Host: mail.google.com","Proxy-Connection: keep-alive","User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"],"line":"CONNECT mail.google.com:443 HTTP/1.1\r\n"},"phase":0,"source":{"id":822,"type":5},"time":"331488980","type":125},
{"params":{"headers":["Host: mail.google.com","Proxy-Connection: keep-alive","User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"],"line":"CONNECT mail.google.com:443 HTTP/1.1\r\n"},"phase":0,"source":{"id":822,"type":5},"time":"331488980","type":129},
{"params":{"byte_count":227},"phase":0,"source":{"id":822,"type":5},"time":"331488980","type":61},
{"phase":2,"source":{"id":822,"type":5},"time":"331488981","type":124},
{"phase":1,"source":{"id":822,"type":5},"time":"331488981","type":126},
{"phase":1,"source":{"id":822,"type":5},"time":"331488981","type":207},
{"params":{"address_family":0,"allow_cached_response":true,"host":"mail.google.com:0","is_speculative":false,"source_dependency":{"id":0,"type":0}},"phase":1,"source":{"id":823,"type":8},"time":"331489008","type":4},
{"params":{"source_dependency":{"id":823,"type":8}},"phase":1,"source":{"id":824,"type":21},"time":"331489008","type":299},
{"params":{"source_dependency":{"id":824,"type":21}},"phase":1,"source":{"id":825,"type":14},"time":"331489008","type":34},
{"params":{"address":"[2001:4860:4860::8888]:53"},"phase":1,"source":{"id":825,"type":14},"time":"331489008","type":70},
{"params":{"net_error":-109},"phase":2,"source":{"id":825,"type":14},"time":"331489008","type":70},
{"phase":2,"source":{"id":825,"type":14},"time":"331489008","type":34},
{"phase":2,"source":{"id":824,"type":21},"time":"331489008","type":299},
{"phase":0,"source":{"id":823,"type":8},"time":"331489008","type":6},
{"phase":2,"source":{"id":823,"type":8},"time":"331489008","type":4},
{"params":{"byte_count":74},"phase":0,"source":{"id":822,"type":5},"time":"331489052","type":63},
{"phase":2,"source":{"id":822,"type":5},"time":"331489052","type":207},
{"params":{"headers":["HTTP/1.1 200 Connection established"]},"phase":0,"source":{"id":822,"type":5},"time":"331489052","type":127},
{"params":{"net_error":-111},"phase":2,"source":{"id":822,"type":5},"time":"331489052","type":126},

如果您需要查看更多日志,我已发布整个日志here

2 个答案:

答案 0 :(得分:0)

有点晚了,但是我自己遇到了这个问题。我的情况是我在CONNECT响应中发送了一个额外的字节。 通过在Chrome中启用NetLog(在一切捕获模式下)发现了这一点:

--> bytes =
  48 54 54 50 2F 31 2E 31  20 32 30 30 20 43 6F 6E   HTTP/1.1 200 Con
  6E 65 63 74 69 6F 6E 20  65 73 74 61 62 6C 69 73   nection establis
  68 65 64 0D 0A 0D 0A 00                            hed.... 

请参阅结尾的00。Chrome(和curl)似乎比Firefox或Safari more strict多,因为您发送给它的整个缓冲区必须是格式正确的HTTP响应。

我建议您capture a full NetLog dump并查看Chrome接收的字节。

答案 1 :(得分:-1)

更改

  

建立HTTP / 1.0 200连接\ r \ n \ r \ n

  

建立HTTP / 1.0 200连接\ r \ n