Invalid HTTP request received #2487
Replies: 2 comments
-
This problem has nothing to do with uvicorn, this is what h11 returns when parsing the message. h11 and httptools behave differently when parsing this message. import h11
request = b'GET /\r\n\r\n'
conn = h11.Connection(h11.SERVER)
conn.receive_data(request)
print(conn.next_event()) import httptools
request = b'GET /\r\n\r\n'
class MyHandler:
def on_url(self, url: bytes) -> None:
print(url)
def on_headers_complete(self) -> None:
http_version = parser.get_http_version()
method = parser.get_method()
print(f"HTTP version: {http_version}, method: {method}")
parser = httptools.HttpRequestParser(MyHandler())
parser.feed_data(request) |
Beta Was this translation helpful? Give feedback.
-
Hi, something is missing in your request:
A minimally valid HTTP (1.0) request should look like this:
But in HTTP version 1.1 (the only one Uvicorn uses),
So don't forget to always add |
Beta Was this translation helpful? Give feedback.
-
Hi.
I am reaching out to seek clarification on a potential issue I have encountered while working with a FastAPI project that utilizes Uvicorn. Specifically, I am unsure whether the behavior I'm observing is a bug or expected functionality.
When I execute the following code snippet:
I receive the following warning on the server:
Invalid HTTP request received.
Given that b'GET /\r\n\r\n' appears to be a valid HTTP request, I would like to understand if this behavior is expected or if there might be an underlying issue in uvicorn.
Server code:
Beta Was this translation helpful? Give feedback.
All reactions