Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access log and multiple headers of the same name #3618

Closed
haverins opened this issue Feb 20, 2019 · 6 comments
Closed

Access log and multiple headers of the same name #3618

haverins opened this issue Feb 20, 2019 · 6 comments
Labels

Comments

@haverins
Copy link

Long story short

I have aiohttp behind haproxy and I'd like to see clients IP in aiohttp access log. Haproxy can forward client IP in (X-Client) http header and I can log that. However, there is edge case where request already has X-Client header. Aiohttp logs 1st occurrence of X-Client and I'd like to log last occurrence.

@aio-libs-bot
Copy link

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are #855 (Support for structured access log), #1652 (Trailer headers), #1504 (Log the names of tests that fail or are skipped?), #2641 (Variety of access logging issues), and #2085 (Document about Access log cause confusion).

@hellysmile
Copy link
Member

Hey You can try https://aiohttp.readthedocs.io/en/stable/logging.html with custom aiohttp.helpers.AccessLogger

@samuelcolvin
Copy link
Member

Are you really sure haproxy doesn't override the X-Client header? That's what most reverse proxies do when they encounter an existing "protected" header.

@haverins
Copy link
Author

haverins commented Feb 20, 2019

@hellysmile What do you mean? I'm already supplying custom log format but %{FOO}i allows me to log only 1st occurrence of the header.

@samuelcolvin From haproxy configuration manual:

Since HAProxy works in reverse-proxy mode, the servers see its IP address as
their client address. This is sometimes annoying when the client's IP address
is expected in server logs. To solve this problem, the well-known HTTP header
"X-Forwarded-For" may be added by HAProxy to all requests sent to the server.
This header contains a value representing the client's IP address. Since this
header is always appended at the end of the existing header list, the server
must be configured to always use the last occurrence of this header only.

It might be possible to overwrite headers with haproxy (it can do lot of things) but that's a bit hacky solution.

@samuelcolvin
Copy link
Member

@hellysmile, means write your own AccessLogger rather than using the default one, as documented at that link.

Example here but that's much more complicated than yours needs to be.

@samuelcolvin samuelcolvin added question StackOverflow and removed enhancement labels Feb 20, 2019
@haverins
Copy link
Author

@samuelcolvin I see. Seems easy enough. Thanks.

@lock lock bot added the outdated label Feb 21, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants