Compare commits
15 Commits
fix-2388-s
...
feat-2394-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92bfeaefd5 | ||
|
|
5a650f5758 | ||
|
|
850b1f432c | ||
|
|
df8480156d | ||
|
|
d0cfb69f43 | ||
|
|
19eee8bfb2 | ||
|
|
625cffb1b9 | ||
|
|
c5ac28cbcd | ||
|
|
e57bea28f7 | ||
|
|
28665e31ce | ||
|
|
9f41936861 | ||
|
|
7835492b09 | ||
|
|
ca3bea3425 | ||
|
|
88ca56dda3 | ||
|
|
d2ab46d70b |
@@ -30,6 +30,7 @@ from types import SimpleNamespace
|
||||
from urllib.parse import parse_qs, parse_qsl, unquote, urlunparse
|
||||
|
||||
from httptools import parse_url # type: ignore
|
||||
from httptools.parser.errors import HttpParserInvalidURLError # type: ignore
|
||||
|
||||
from sanic.compat import CancelledErrors, Header
|
||||
from sanic.constants import DEFAULT_HTTP_CONTENT_TYPE
|
||||
@@ -130,7 +131,12 @@ class Request:
|
||||
|
||||
self.raw_url = url_bytes
|
||||
# TODO: Content-Encoding detection
|
||||
self._parsed_url = parse_url(url_bytes)
|
||||
try:
|
||||
self._parsed_url = parse_url(url_bytes)
|
||||
except HttpParserInvalidURLError as InvalidURLError:
|
||||
raise InvalidUsage(
|
||||
"URL is invalid or malformed"
|
||||
) from InvalidURLError
|
||||
self._id: Optional[Union[uuid.UUID, str, int]] = None
|
||||
self._name: Optional[str] = None
|
||||
self.app = app
|
||||
|
||||
@@ -21,3 +21,25 @@ def test_bad_request_response(app):
|
||||
app.run(host="127.0.0.1", port=42101, debug=False)
|
||||
assert lines[0] == b"HTTP/1.1 400 Bad Request\r\n"
|
||||
assert b"Bad Request" in lines[-2]
|
||||
|
||||
|
||||
def test_malformed_uri_bad_request(app):
|
||||
lines = []
|
||||
|
||||
app.get("/")(lambda x: ...)
|
||||
|
||||
@app.listener("after_server_start")
|
||||
async def _request(sanic, loop):
|
||||
connect = asyncio.open_connection("127.0.0.1", 42101)
|
||||
reader, writer = await connect
|
||||
writer.write(b"GET /\r\nHost: ---.com\r\n\r\n")
|
||||
while True:
|
||||
line = await reader.readline()
|
||||
if not line:
|
||||
break
|
||||
lines.append(line)
|
||||
app.stop()
|
||||
|
||||
app.run(host="127.0.0.1", port=42101, debug=False)
|
||||
assert lines[0] == b"HTTP/1.1 400 Bad Request\r\n"
|
||||
assert b"Bad Request" in lines[-2]
|
||||
Reference in New Issue
Block a user