jech / polipo

The Polipo caching HTTP proxy
http://www.pps.jussieu.fr/~jch/software/polipo/
MIT License
1.8k stars 354 forks source link

Handling server replies with "Upgrade" header (HTTP/2 switch) #81

Closed voyageur closed 8 years ago

voyageur commented 8 years ago

Servers supporting HTTP/2 can enable an upgrade path to switch to HTTP/2 from plain text HTTP/1.1. For example, this is the H2Upgrade directive in Apache 2.4: https://httpd.apache.org/docs/2.4/mod/mod_http2.html#h2upgrade

As a result, plain-text queries will have a server reply header "Upgrade", which is blocked by polipo and triggers a 502 Couldn't parse server headers.

Skipping the full HTTP/2 support, this header should be ignored to allow the connection to go on in HTTP/1.1. I disabled the error trigger on Upgrade in httpParseHeaders(), and can browse this kind of sites via polipo again (personal cache server). But I am not sure this change is sufficient to properly handle the Upgrade header (if used to switch to websockets for example).

An example site:

% curl -I http://www.dumbingofage.com/
HTTP/1.1 200 OK
Date: Fri, 26 Feb 2016 10:08:25 GMT
Server: Apache/2.4.18 (Unix)
X-Powered-By: PHP/5.6.15
Vary: Accept-Encoding,Cookie
Cache-Control: max-age=3, must-revalidate
WP-Super-Cache: Served supercache file from PHP
Upgrade: h2,h2c
Connection: Upgrade
Content-Length: 68658
Content-Type: text/html; charset=UTF-8
jech commented 8 years ago

Yes, it should be enough — polipo will not forward headers that are listed in the Connection header. I'll be grateful for a patch.

jech commented 8 years ago

Fixed in 726e1390f1a0978f440ce8b216d7e54f37212da0.