How to print all request headers? #2880
-
When I run this app to try to print all the request headers:
... I get the following error:
I feel like I'm misunderstanding something. Can anyone point out what I'm doing wrong? Also, the Default signature namespace section of the docs mentions that I can place the
... I get the following error when I try to run the app:
Am I doing something wrong here as well? I'm using Litestar version 2.4.3. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Try wrapping |
Beta Was this translation helpful? Give feedback.
-
Does this do it for you? from litestar import Litestar, get, Request
@get("/", sync_to_thread=False)
def index(request: Request) -> str:
print("headers:", request.headers.to_header_list())
return "Hello, world!"
app = Litestar([index]) |
Beta Was this translation helpful? Give feedback.
-
Hi @elliotwaite, unfortunately, you've come across a bug that can't be fixed until version 3 because it would constitute a breaking change; The headers injected into the route handler via the |
Beta Was this translation helpful? Give feedback.
Hi @elliotwaite, unfortunately, you've come across a bug that can't be fixed until version 3 because it would constitute a breaking change; The headers injected into the route handler via the
headers
parameter isn't actually aHeaders
instance but adict
. For now, if you need access to aHeaders
instance, you'll have to use the method @Alc-Alc provided. If you're fine with a dict, you can just typeheaders
as a dict.