Skip to content

Commit 6a73431

Browse files
Fix invalid scheme errors (#403)
* Version 0.13.6 * Fix broken error messaging when URL scheme is missing, or a non HTTP(S) scheme is used. * Update CHANGELOG.md
1 parent c501208 commit 6a73431

3 files changed

Lines changed: 22 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## Master
8+
9+
- Fix broken error messaging when URL scheme is missing, or a non HTTP(S) scheme is used. (Pull #403)
10+
711
## 0.13.6 (June 15th, 2021)
812

913
### Fixed

httpcore/_async/connection_pool.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,16 @@ async def handle_async_request(
195195
stream: AsyncByteStream,
196196
extensions: dict,
197197
) -> Tuple[int, Headers, AsyncByteStream, dict]:
198+
if not url[0]:
199+
raise UnsupportedProtocol(
200+
"Request URL missing either an 'http://' or 'https://' protocol."
201+
)
202+
198203
if url[0] not in (b"http", b"https"):
199-
scheme = url[0].decode("latin-1")
200-
host = url[1].decode("latin-1")
201-
if scheme == "":
202-
raise UnsupportedProtocol(
203-
f"The request to '://{host}/' is missing either an 'http://' \
204-
or 'https://' protocol."
205-
)
206-
else:
207-
raise UnsupportedProtocol(
208-
f"The request to '{scheme}://{host}' has \
209-
an unsupported protocol {scheme!r}"
210-
)
204+
protocol = url[0].decode("ascii")
205+
raise UnsupportedProtocol(
206+
f"Request URL has an unsupported protocol '{protocol}://'."
207+
)
211208

212209
if not url[1]:
213210
raise LocalProtocolError("Missing hostname in URL.")

httpcore/_sync/connection_pool.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,16 @@ def handle_request(
195195
stream: SyncByteStream,
196196
extensions: dict,
197197
) -> Tuple[int, Headers, SyncByteStream, dict]:
198+
if not url[0]:
199+
raise UnsupportedProtocol(
200+
"Request URL missing either an 'http://' or 'https://' protocol."
201+
)
202+
198203
if url[0] not in (b"http", b"https"):
199-
scheme = url[0].decode("latin-1")
200-
host = url[1].decode("latin-1")
201-
if scheme == "":
202-
raise UnsupportedProtocol(
203-
f"The request to '://{host}/' is missing either an 'http://' \
204-
or 'https://' protocol."
205-
)
206-
else:
207-
raise UnsupportedProtocol(
208-
f"The request to '{scheme}://{host}' has \
209-
an unsupported protocol {scheme!r}"
210-
)
204+
protocol = url[0].decode("ascii")
205+
raise UnsupportedProtocol(
206+
f"Request URL has an unsupported protocol '{protocol}://'."
207+
)
211208

212209
if not url[1]:
213210
raise LocalProtocolError("Missing hostname in URL.")

0 commit comments

Comments
 (0)