def as_http_request_context(self): scheme, domain_or_ip, port, path, _ = urlsplit(self.url) host = scheme + "://" + domain_or_ip if port: host += ":" + str(port) body_params, renderer = self.post_data return HttpRequestContext( host=host, method=self.method, url_path=path, query_params=self.query_string, headers=self.headers, renderer=renderer, body_params=body_params )
def test_urlsplit_with_non_http_schema(self): scheme, host, port = urlsplit("ftp://myhost.com") self.assertEqual(scheme, 'ftp') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')
def test_urlsplit_without_end_slash(self): scheme, host, port = urlsplit("myhost.com") self.assertEqual(scheme, None) self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')
def test_urlsplit_https_and_port(self): scheme, host, port = urlsplit("https://myhost.com:66/") self.assertEqual(scheme, 'https') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '66')
def test_urlsplit_https_schema(self): scheme, host, port = urlsplit("https://myhost.com/") self.assertEqual(scheme, 'https') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')
def test_urlsplit_empty_schema(self): scheme, host, port = urlsplit("://myhost.com/") self.assertEqual(scheme, '') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')
def test_urlsplit_localhost(self): scheme, host, port = urlsplit("http://localhost:8080") self.assertEqual(scheme, 'http') self.assertEqual(host, 'localhost') self.assertEqual(port, '8080')
def test_urlsplit_without_end_slash(self): scheme, host, port, _, _ = urlsplit("myhost.com") self.assertEqual(scheme, None) self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')
def test_urlsplit_https_and_port(self): scheme, host, port, _, _ = urlsplit("https://myhost.com:66/") self.assertEqual(scheme, 'https') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '66')
def test_urlsplit_https_schema(self): scheme, host, port, _, _ = urlsplit("https://myhost.com/") self.assertEqual(scheme, 'https') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')
def test_urlsplit_empty_schema(self): scheme, host, port, _, _ = urlsplit("://myhost.com/") self.assertEqual(scheme, '') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')
def test_urlsplit_localhost(self): scheme, host, port, _, _ = urlsplit("http://localhost:8080") self.assertEqual(scheme, 'http') self.assertEqual(host, 'localhost') self.assertEqual(port, '8080')
def test_urlsplit_with_non_http_schema(self): scheme, host, port, _, _ = urlsplit("ftp://myhost.com") self.assertEqual(scheme, 'ftp') self.assertEqual(host, 'myhost.com') self.assertEqual(port, '')