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

'Host' header contains :80 or :443 #280

Closed
paambaati opened this issue Mar 27, 2018 · 2 comments
Closed

'Host' header contains :80 or :443 #280

paambaati opened this issue Mar 27, 2018 · 2 comments
Assignees

Comments

@paambaati
Copy link
Contributor

paambaati commented Mar 27, 2018

Most clients (including curl) and browsers leave out the :80 & :443 port suffixes in the Host header, and include it only when it is neither of the two. Dropping the port prefix for known services is still RFC-compliant; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23

urllib, however, always includes the port and this can cause incompatibilities with other server implementations.

Examples of other projects stripping the port suffix —

  1. Ruby - https://github.com/ruby/ruby/blob/d46336e71731aa64d71d4573b2741b7de43ec340/lib/net/http/generic_request.rb#L18
  2. Request module - Port 80 is included in the 'Host' request field (instead of defaulted) when it isn't with other popular HTTP clients request/request#515 (comment)
  3. Omit port in Host header for default ports waterlink/rack-reverse-proxy#3
  4. Use request.hostname, not request.headers.host twilio/twilio-node#151
  5. https://stackoverflow.com/a/19169664
@fengmk2
Copy link
Member

fengmk2 commented Mar 27, 2018

urllib won't auto set 'Host' header by default.
Is there any way to repeat your problem?

@fengmk2 fengmk2 self-assigned this Mar 27, 2018
@paambaati
Copy link
Contributor Author

I'll close this now. I tried replicating this with a minimal setup, and it works and I see no issue. This must've been injected elsewhere in our stack.

Thanks for responding, and sorry for the trouble @fengmk2!

For anyone else interested, here's a simple echo server that logs request headers —

// Server that listens on 'localhost:80'.
var http = require('http');
 
http.createServer(function(request,response){
	console.log('HEADERS: ', request.headers);
	response.writeHead(200);
	request.on('data',function(message){
		response.write(message);
	});
	request.on('end',function(){
		response.end();
	});
}).listen(80);

And a simple request to the echo server —

// Send a request to 'localhost:80' using urllib
var urllib = require('urllib');

urllib.request('http://localhost:80', function (err, data, res) {
  if (err) {
    throw err; // you need to handle error
  }
  console.log(res.statusCode);
  console.log(res.headers);
  // data is Buffer instance
  console.log(data.toString());
});

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

No branches or pull requests

2 participants