Removes extra slash on endpoints without a path
Change-Id: I5ce54117c5ac276fb9629c71eb16db88e078c947 Fixes: bug #1179984
This commit is contained in:
parent
c120aff87f
commit
d8a537c7fe
@ -180,7 +180,9 @@ class HTTPClient(object):
|
|||||||
kwargs['headers'] = self.encode_headers(kwargs['headers'])
|
kwargs['headers'] = self.encode_headers(kwargs['headers'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn_url = posixpath.normpath('%s/%s' % (self.endpoint_path, url))
|
if self.endpoint_path:
|
||||||
|
url = '%s/%s' % (self.endpoint_path, url)
|
||||||
|
conn_url = posixpath.normpath(url)
|
||||||
# Note(flaper87): Ditto, headers / url
|
# Note(flaper87): Ditto, headers / url
|
||||||
# encoding to make httplib happy.
|
# encoding to make httplib happy.
|
||||||
conn_url = strutils.safe_encode(conn_url)
|
conn_url = strutils.safe_encode(conn_url)
|
||||||
|
@ -89,6 +89,27 @@ class TestClient(testtools.TestCase):
|
|||||||
encoded = self.client.encode_headers(headers)
|
encoded = self.client.encode_headers(headers)
|
||||||
self.assertEqual(encoded["test"], "ni\xc3\xb1o")
|
self.assertEqual(encoded["test"], "ni\xc3\xb1o")
|
||||||
|
|
||||||
|
def test_raw_request(self):
|
||||||
|
" Verify the path being used for HTTP requests reflects accurately. "
|
||||||
|
|
||||||
|
def check_request(method, path, **kwargs):
|
||||||
|
self.assertEqual(method, 'GET')
|
||||||
|
# NOTE(kmcdonald): See bug #1179984 for more details.
|
||||||
|
self.assertEqual(path, '/v1/images/detail')
|
||||||
|
|
||||||
|
httplib.HTTPConnection.request(
|
||||||
|
mox.IgnoreArg(),
|
||||||
|
mox.IgnoreArg(),
|
||||||
|
headers=mox.IgnoreArg()).WithSideEffects(check_request)
|
||||||
|
|
||||||
|
# fake the response returned by httplib
|
||||||
|
fake = utils.FakeResponse({}, StringIO.StringIO('Ok'))
|
||||||
|
httplib.HTTPConnection.getresponse().AndReturn(fake)
|
||||||
|
self.mock.ReplayAll()
|
||||||
|
|
||||||
|
resp, body = self.client.raw_request('GET', '/v1/images/detail')
|
||||||
|
self.assertEqual(resp, fake)
|
||||||
|
|
||||||
def test_connection_refused_raw_request(self):
|
def test_connection_refused_raw_request(self):
|
||||||
"""
|
"""
|
||||||
Should receive a CommunicationError if connection refused.
|
Should receive a CommunicationError if connection refused.
|
||||||
|
Loading…
Reference in New Issue
Block a user