]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Validate URL scheme and host in request
authorKim Christie <kim@encode.io>
Wed, 17 Dec 2025 13:57:27 +0000 (13:57 +0000)
committerGitHub <noreply@github.com>
Wed, 17 Dec 2025 13:57:27 +0000 (13:57 +0000)
Add validation for URL scheme and netloc in request

src/ahttpx/_request.py

index 78b82282d067245665c2e5f2c07aaa0d3c654a38..a247b8b45856f78b5b9e3b08dbae1394cf4c1ef8 100644 (file)
@@ -29,6 +29,11 @@ class Request:
         if "Host" not in self.headers:
             self.headers = self.headers.copy_set("Host", self.url.netloc)
 
+        if self.url.scheme not in ('http', 'https'):
+            raise ValueError(f'Invalid scheme for URL {str(self.url)!r}.')
+        if not self.url.netloc:
+            raise ValueError(f'Missing host for URL {str(self.url)!r}.')
+
         if content is not None:
             if isinstance(content, bytes):
                 self.stream = ByteStream(content)