Refactor http_connect() to use http_connect_raw()
Change-Id: I889c5eecf860cc947763c5d79148419f9741a2c2 Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
parent
c85d2ace93
commit
259aafb6f0
@ -126,27 +126,14 @@ def http_connect(ipaddr, port, device, partition, method, path,
|
|||||||
:param ssl: set True if SSL should be used (default: False)
|
:param ssl: set True if SSL should be used (default: False)
|
||||||
:returns: HTTPConnection object
|
:returns: HTTPConnection object
|
||||||
"""
|
"""
|
||||||
if not port:
|
|
||||||
port = 443 if ssl else 80
|
|
||||||
if ssl:
|
|
||||||
conn = HTTPSConnection('%s:%s' % (ipaddr, port))
|
|
||||||
else:
|
|
||||||
conn = BufferedHTTPConnection('%s:%s' % (ipaddr, port))
|
|
||||||
if isinstance(path, unicode):
|
if isinstance(path, unicode):
|
||||||
try:
|
try:
|
||||||
path = path.encode("utf-8")
|
path = path.encode("utf-8")
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
pass # what should I do?
|
pass # what should I do?
|
||||||
path = quote('/' + device + '/' + str(partition) + path)
|
path = quote('/' + device + '/' + str(partition) + path)
|
||||||
if query_string:
|
return http_connect_raw(
|
||||||
path += '?' + query_string
|
ipaddr, port, method, path, headers, query_string, ssl)
|
||||||
conn.path = path
|
|
||||||
conn.putrequest(method, path, skip_host=(headers and 'Host' in headers))
|
|
||||||
if headers:
|
|
||||||
for header, value in headers.iteritems():
|
|
||||||
conn.putheader(header, str(value))
|
|
||||||
conn.endheaders()
|
|
||||||
return conn
|
|
||||||
|
|
||||||
|
|
||||||
def http_connect_raw(ipaddr, port, method, path, headers=None,
|
def http_connect_raw(ipaddr, port, method, path, headers=None,
|
||||||
|
Loading…
Reference in New Issue
Block a user