From: Kim Christie Date: Wed, 17 Dec 2025 13:57:56 +0000 (+0000) Subject: Validate URL scheme and ensure host presence X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b99aaed1194812edf11f5d265f0d761fd2274c5;p=thirdparty%2Fhttpx.git Validate URL scheme and ensure host presence Add validation for URL scheme and netloc in requests. --- diff --git a/src/httpx/_request.py b/src/httpx/_request.py index 1b739b18..03c78dfe 100644 --- a/src/httpx/_request.py +++ b/src/httpx/_request.py @@ -28,6 +28,11 @@ class Request: # A client MUST include a Host header field in all HTTP/1.1 request messages. 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):