pires / go-proxyproto

A Go library implementation of the PROXY protocol, versions 1 and 2.
Apache License 2.0
478 stars 107 forks source link

v1: fix command always LOCAL #64

Closed bohanyang closed 3 years ago

bohanyang commented 3 years ago

The changes in #61 overrides all header.Command to LOCAL (which was set to PROXY by initVersion1) unconditionally.

https://github.com/pires/go-proxyproto/blob/b6f440c01c68bf65792f463adcc71eb620fb0484/v1.go#L55-L60

This makes these functions returning the original addresses rather than the addresses contained in the proxy header.

https://github.com/pires/go-proxyproto/blob/b6f440c01c68bf65792f463adcc71eb620fb0484/protocol.go#L127-L155

Unfortunately, the problem was not revealed, since the EqualsTo function, which is used by the tests to compare actual and expected headers, straightly returns true when the command is LOCAL, and the command is not being compared.

https://github.com/pires/go-proxyproto/blob/b6f440c01c68bf65792f463adcc71eb620fb0484/header.go#L150-L170

This PR also updated the condition that checks the token length, made it to make sense.

The comments for ProtocolVersionAndCommand are also updated, made it less confusing.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.007%) to 94.223% when pulling 43ce4efcec8621dbb090ce8c68ef042a2c678c5f on bohanyang:fix-v1-command into b6f440c01c68bf65792f463adcc71eb620fb0484 on pires:main.

bohanyang commented 3 years ago

Done fixing the comments!

pires commented 3 years ago

https://github.com/pires/go-proxyproto/releases/tag/v0.4.2