Skip to content
Merged
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
15 changes: 6 additions & 9 deletions adafruit_httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from errno import EAGAIN, ECONNRESET
import os
import re

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer.git"
Expand Down Expand Up @@ -60,8 +59,6 @@ def __str__(self):


class _HTTPRequest:
_REQUEST_RE = re.compile(r"(\S+)\s+(\S+)\s")

def __init__(
self, path: str = "", method: str = "", raw_request: bytes = None
) -> None:
Expand All @@ -70,12 +67,12 @@ def __init__(
self.method = method
else:
# Parse request data from raw request
match = self._REQUEST_RE.match(raw_request.decode("utf8"))
if match:
self.path = match.group(2)
self.method = match.group(1)
else:
raise ValueError("Unparseable raw_request:", raw_request)
request_text = raw_request.decode("utf8")
first_line = request_text[: request_text.find("\n")]
try:
(self.method, self.path, _httpversion) = first_line.split()
except ValueError as exc:
raise ValueError("Unparseable raw_request: ", raw_request) from exc

def __hash__(self) -> int:
return hash(self.method) ^ hash(self.path)
Expand Down