Removes extra slash on endpoints without a path

Change-Id: I5ce54117c5ac276fb9629c71eb16db88e078c947
Fixes: bug #1179984
This commit is contained in:
Kevin McDonald 2013-05-14 10:31:45 -05:00 committed by Gerrit Code Review
parent c120aff87f
commit d8a537c7fe
2 changed files with 24 additions and 1 deletions

View File

@ -180,7 +180,9 @@ class HTTPClient(object):
kwargs['headers'] = self.encode_headers(kwargs['headers'])
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
# encoding to make httplib happy.
conn_url = strutils.safe_encode(conn_url)

View File

@ -89,6 +89,27 @@ class TestClient(testtools.TestCase):
encoded = self.client.encode_headers(headers)
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):
"""
Should receive a CommunicationError if connection refused.