Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ def parse_request(self):
requestline = str(self.raw_requestline, 'iso-8859-1')
requestline = requestline.rstrip('\r\n')
self.requestline = requestline

# Detect TLS handshake attempt (common when browser forces HTTPS)
if self.raw_requestline[0] == 0x16: # First TLS handshake bytes
self.requestline = "[TLS handshake bytes]"
self.send_error(
HTTPStatus.BAD_REQUEST,
"Unsupported protocol: HTTPS is not available")
return False

words = requestline.split()
if len(words) == 0:
return False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Detect TLS handshake attempt in :class:`http.server.BaseHTTPRequestHandler` to
more clear the output. Patch by Semyon Moroz.
Loading