Allow specifically accessing the proxy source address #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This distinguishing the case where a source address could not be
determined, i.e. because the proxy header could not be read.
I think this PR makes sense in some cases. For my use-case, we have a proxy connection (which should always have the proxy header), and we want to know the ip of the remote client.
Our code naively looks like so:
This code, unfortunately, sometimes gets the proxy's address instead of the remote client's address (i.e. in cases where the system's under load and the proxy server has issues writing the header).
This is because the
RemoteAddr()
call chooses to return the underlying connection's address in some cases:go-proxyproto/protocol.go
Lines 164 to 170 in f0b8253
Basically,
checkPrefixOnce
may error out, and if it does I want to know, but that error doesn't get bubbled up fromRemoteAddr
orAccept
.One alternative solution we could probably take is the following:
This isn't tested, but I think that would also solve the problem I'm facing (since
Read
reads the header, and also does bubble up errors it encounters).However, it seems inelegant compared to having a more explicit method to distinguish whether the connection is proxied or not.