Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP/1.0 proxied as HTTP/1.1 #59

Closed
fidian opened this issue Jun 9, 2011 · 10 comments
Closed

HTTP/1.0 proxied as HTTP/1.1 #59

fidian opened this issue Jun 9, 2011 · 10 comments

Comments

@fidian
Copy link

fidian commented Jun 9, 2011

Sample code:

require('http-proxy').createServer(80, 'localhost').listen(8001); 

Sample request:

GET /phpinfo.php HTTP/1.0
Host: localhost:8001

Request that goes to the server:

GET /phpinfo.php HTTP/1.1
host: localhost:8001
x-forwarded-for: 127.0.0.1
x-forwarded-port: 38349
x-forwarded-proto: http
Connection: close

The server's response for this page looks like this:

HTTP/1.1 200 OK
Date: Thu, 09 Jun 2011 14:53:41 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.2
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

259f
<html><head>...lots of HTML

The response to the client looks identical. This, unfortunately, breaks the HTTP/1.0 response since now we are both sending an HTTP/1.1 status and we are doing chunked encoding. The HTTP/1.0 client can't understand this.

The fix: Make the request to the server an HTTP/1.0 request to mirror the client's desires perfectly.

@indexzero
Copy link
Contributor

@fidian Can you provide a complete repro including the PHP script that I should use to reproduce the issue?

@fidian
Copy link
Author

fidian commented Jun 13, 2011

PHP code to make the request:

file_get_contents('http://localhost:8001/phpinfo.php');

PHP code to handle the request

phpinfo();

You need to not write out gzipped data and write a large enough amount of data so that PHP will automatically chunk the reply. The above should do it.

@fidian fidian closed this as completed Jun 13, 2011
@fidian fidian reopened this Jun 13, 2011
@indexzero
Copy link
Contributor

@fidian here is the simplest repro for this issue:

  $ cd /path/to/node-http-proxy
  $ forever start examples/standalone-proxy-server.js
  $ curl -0 -v http://localhost:8004/
  * About to connect() to localhost port 8004 (#0)
*   Trying ::1... Connection refused
*   Trying fe80::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8004 (#0)
> GET / HTTP/1.0
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: localhost:8004
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-type: text/plain
< connection: close
< transfer-encoding: chunked
< 
request successfully proxied to: /
{
  "user-agent": "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3",
  "host": "localhost:8004",
  "accept": "*/*",
  "x-forwarded-for": "127.0.0.1",
  "x-forwarded-port": "53575",
  "x-forwarded-proto": "http",
  "connection": "close"
* Closing connection #0
}

Unfortunately, it seems that this is by design in node.js core. This is the status line written to every ServerResponse object in core: https://github.com/joyent/node/blob/v0.4.8/lib/http.js#L833-834, which doesn't seem to be configurable anywhere.

Maybe @ry or @felixge can comment on if outgoing HTTP/1.0 requests are going to be supported in core.

@felixge
Copy link

felixge commented Jun 26, 2011

As far as I know node only supports http 1.1, not sure if that is going to change.

@indexzero
Copy link
Contributor

@felixge Thank you for clarifying. I am going to close this as wont-fix.

@ry
Copy link

ry commented Jun 26, 2011

You shouldn't send chunked responses to http 1.0 clients - Node should know this. HTTP 1.1 servers are backwards compatible. It certainly is a bug....

@felixge
Copy link

felixge commented Jun 26, 2011

You shouldn't send chunked responses to http 1.0 clients - Node should know this.

That would mean we have to buffer the whole response data for http 1.0 clients, right?

@indexzero
Copy link
Contributor

@ry Thanks. I'll reopen this. I've opened an associated bug on node here: nodejs/node-v0.x-archive#1234

@indexzero indexzero reopened this Jun 26, 2011
@ry
Copy link

ry commented Jun 26, 2011

@felixge the response can be terminated by closing the connection

@majek
Copy link

majek commented Sep 15, 2011

I'm sure you're aware of the severity of this bug, but let me emphasize it again. Sending 'Transfer-encoding: chunked' response to clients that are speaking http1.0 effectively means that node-http-proxy will not work from behind http1.0 proxies, like squid 2.5.

Squid website says:
"Squid is a fully-featured HTTP/1.0 proxy which is almost (but not quite - we're getting there!) HTTP/1.1 compliant."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants