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

Safari doesn't work through Alpaca #21

Closed samuong closed 4 years ago

samuong commented 4 years ago

Here's what's going on:

  1. Safari sends a CONNECT request to Alpaca
  2. Alpaca responds with a 200 OK, and Go's ResponseWriter.WriteHeader() will automatically add Transfer-Encoding: chunked to the response header
  3. It then blindly copies data back and forth between the client and the server, but this data is not chunk encoded, and Safari's chunk decoder appears to fail as a result

According to https://tools.ietf.org/html/rfc7231#section-4.3.6:

A server MUST NOT send any Transfer-Encoding or Content-Length header fields in a 2xx (Successful) response to CONNECT. A client MUST ignore any Content-Length or Transfer-Encoding header fields received in a successful response to CONNECT.

It's not clear to me why Safari isn't ignoring the Transfer-Encoding header from Alpaca, but I think it should.

This also needs to be fixed in Alpaca by writing the CONNECT response directly to the connection (using Conn.Write()), rather than using Go's ResponseWriter.