def get(self, path): """Handle GET requests. Receive a path that will be used as part of the resulting URL used to retrieve the response. The response will then be sent back to the client. """ url = join_url(self.target_url, path, self.request.query) response = yield self.send_request(url) if response is not None: self.send_response(response)
def test_strip_slashes(self): # Path slashes are properly stripped. pairs = [ ("http://www.example.com", "path1/path2"), ("http://www.example.com/", "path1/path2"), ("http://www.example.com", "/path1/path2"), ("http://www.example.com/", "/path1/path2"), ] expected_url = "http://www.example.com/path1/path2" for base_url, path in pairs: url = utils.join_url(base_url, path, "") self.assertEqual(expected_url, url, "{} + {} -> {}".format(base_url, path, url))
def test_strip_slashes(self): # Path slashes are properly stripped. pairs = [ ('http://www.example.com', 'path1/path2'), ('http://www.example.com/', 'path1/path2'), ('http://www.example.com', '/path1/path2'), ('http://www.example.com/', '/path1/path2'), ] expected_url = 'http://www.example.com/path1/path2' for base_url, path in pairs: url = utils.join_url(base_url, path, '') self.assertEqual(expected_url, url, '{} + {} -> {}'.format(base_url, path, url))
def test_strip_slashes(self): # Path slashes are properly stripped. pairs = [ ('http://www.example.com', 'path1/path2'), ('http://www.example.com/', 'path1/path2'), ('http://www.example.com', '/path1/path2'), ('http://www.example.com/', '/path1/path2'), ] expected_url = 'http://www.example.com/path1/path2' for base_url, path in pairs: url = utils.join_url(base_url, path, '') self.assertEqual( expected_url, url, '{} + {} -> {}'.format(base_url, path, url))
def get(self, path): """Handle GET requests. See the ProxyHandler.get method. Override to handle the case when a charm icon is not found. """ url = join_url(self.target_url, path, self.request.query) response = yield self.send_request(url) if response is not None: if response.code == 404 and self._charm_icon_requested(path): # This is a request for a charm icon file, and the icon is not # found: redirect to the fallback icon hosted on charmworld. self.redirect(self.default_charm_icon_url) else: # Return the response to the client as usual. self.send_response(response)
def test_no_query(self): # The query part can be an empty string. url = utils.join_url('https://example.com:8888', 'path2', '') self.assertEqual('https://example.com:8888/path2', url)
def test_no_path(self): # The function can be used to just join the base URL and the query. url = utils.join_url('https://example.com:8888', '', 'arg1=value1') self.assertEqual('https://example.com:8888/?arg1=value1', url)
def test_url_parts(self): # The URL includes the base part, the path and the given query. url = utils.join_url( 'https://example.com:8888/path1', 'path2', 'arg1=value1') self.assertEqual( 'https://example.com:8888/path1/path2?arg1=value1', url)
def test_url_parts(self): # The URL includes the base part, the path and the given query. url = utils.join_url('https://example.com:8888/path1', 'path2', 'arg1=value1') self.assertEqual('https://example.com:8888/path1/path2?arg1=value1', url)
def test_no_query(self): # The query part can be an empty string. url = utils.join_url("https://example.com:8888", "path2", "") self.assertEqual("https://example.com:8888/path2", url)