diff options
author | Zuul <zuul@review.opendev.org> | 2022-08-11 18:42:56 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-08-11 18:42:56 +0000 |
commit | befcca345b233cae28cd320f20592aaab3fa289a (patch) | |
tree | 98f7bc6188b5ea32a5124552b300ada958daf0e4 | |
parent | 9605ff108119097955c030603319ea96106b59ca (diff) | |
parent | 951a9f535e18571d82f1dbe30e94740601f84ffe (diff) | |
download | glance_store-befcca345b233cae28cd320f20592aaab3fa289a.tar.gz |
Merge "Do not loose url queries on redirects"
-rw-r--r-- | glance_store/_drivers/http.py | 13 | ||||
-rw-r--r-- | glance_store/tests/unit/test_http_store.py | 9 |
2 files changed, 20 insertions, 2 deletions
diff --git a/glance_store/_drivers/http.py b/glance_store/_drivers/http.py index 79d3ab7..0d55e4b 100644 --- a/glance_store/_drivers/http.py +++ b/glance_store/_drivers/http.py @@ -105,18 +105,26 @@ class StoreLocation(glance_store.location.StoreLocation): self.user = self.specs.get('user') self.password = self.specs.get('password') self.path = self.specs.get('path') + self.query = self.spec.get('query') def _get_credstring(self): if self.user: return '%s:%s@' % (self.user, self.password) return '' + def _get_query_string(self): + if self.query: + return "?%s" % self.query + return "" + def get_uri(self): - return "%s://%s%s%s" % ( + return "%s://%s%s%s%s" % ( self.scheme, self._get_credstring(), self.netloc, - self.path) + self.path, + self._get_query_string() + ) def parse_uri(self, uri): """ @@ -164,6 +172,7 @@ class StoreLocation(glance_store.location.StoreLocation): self.netloc = netloc self.path = path + self.query = pieces.query def http_response_iterator(conn, response, size): diff --git a/glance_store/tests/unit/test_http_store.py b/glance_store/tests/unit/test_http_store.py index 4eafb88..ca3a9c6 100644 --- a/glance_store/tests/unit/test_http_store.py +++ b/glance_store/tests/unit/test_http_store.py @@ -184,6 +184,15 @@ class TestHttpStore(base.StoreBaseTest, self.assertRaises(exceptions.BadStoreUri, location.get_location_from_uri, uri) + def test_http_store_location_get_uri(self): + """Test for HTTP URI with and without query""" + uris = ["http://netloc/path/to/file.tar.gz" + "http://netloc/path/to/file.tar.gz?query=text", + ] + for uri in uris: + loc = location.get_location_from_uri(uri, conf=self.conf) + self.assertEqual(uri, loc.store_location.get_uri()) + def test_http_get_raises_remote_service_unavailable(self): """Test http store raises RemoteServiceUnavailable.""" uri = "http://netloc/path/to/file.tar.gz" |