Fixed custom Host

Closes #235
This commit is contained in:
Jakub Roztocil 2014-06-28 13:24:14 +02:00
parent 8c892edd4f
commit 040d981f00
2 changed files with 18 additions and 2 deletions

View File

@ -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)

17
tests/test_regressions.py Normal file
View File

@ -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