samuong / alpaca

A local HTTP proxy for command-line tools. Supports PAC scripts and NTLM authentication.
Apache License 2.0
184 stars 31 forks source link

Write CONNECT response in a single call to Conn.Write() #117

Closed samuong closed 8 months ago

samuong commented 8 months ago

This introduces a few changes from the previous version:

  1. If we build an http.Response and call its Write() function, it will write the response line-by-line. This seems to be the cause of some flakiness with clients that start tunnel mode after the status line, rather than after the response header, as per RFC9110 9.3.6.

  2. We only support HTTP 1.0 and 1.1. We no longer just blindly copy over the HTTP version from the client request.

  3. The status code is still 200 but the status message has changed from "OK" to "Connection Established", in line with what other proxies are doing (I tested Squid, Martian and Zscaler). Clients ignore this anyway, going with the status code, so this shouldn't matter.

  4. We no longer send a 'Connection: close' header with the response. This is redundant in a CONNECT request, and follows what other proxies (Squid, Martian and Zscaler) do.