diff --git a/httpie/models.py b/httpie/models.py index f6b9dff9..af6163fd 100644 --- a/httpie/models.py +++ b/httpie/models.py @@ -102,8 +102,7 @@ class HTTPRequest(HTTPMessage): ) headers = dict(self._orig.headers) - - if 'Host' not in headers: + if 'Host' not in self._orig.headers: headers['Host'] = url.netloc.split('@')[-1] headers = ['%s: %s' % (name, value) diff --git a/tests/test_regressions.py b/tests/test_regressions.py new file mode 100644 index 00000000..8c21d1d3 --- /dev/null +++ b/tests/test_regressions.py @@ -0,0 +1,17 @@ +"""Miscellaneous regression tests""" +import socket + +from utils import http, HTTP_OK + + +def test_Host_header_overwrite(): + """ + https://github.com/jakubroztocil/httpie/issues/235 + + """ + host = 'httpbin.org' + url = 'http://{httpbin_ip}/get'.format( + httpbin_ip=socket.gethostbyname(host)) + r = http('--print=hH', url, 'host:{}'.format(host)) + assert HTTP_OK in r + assert r.lower().count('host:') == 1