pgjones / hypercorn

Hypercorn is an ASGI and WSGI Server based on Hyper libraries and inspired by Gunicorn.
MIT License
1.17k stars 104 forks source link

How do I log username in access log? #230

Closed nabheet closed 5 months ago

nabheet commented 6 months ago

I have a Fast API application that uses Bearer tokens. Is there was way for me to provide hypercorn the username or some identifier of the user/service-account associated with the bearer token from Fast API? So that it can be logged in the access log.

EDIT 1: I just realized I could set a response header in fast api and have hypercorn log it in the access log. Is that the best way to accomplish this?

pgjones commented 5 months ago

I think the response header would work. Although it might make more sense to access log in FastAPI rather than Hypercorn - there is a good discussion of options here