Conversation

padremortius

Add middleware for support proxy headers (based on code gorilla mux handler https://.com/gorilla/handlers/blob/master/proxy_headers.go)

}

if c.Request().Header.Get(echo.HeaderXForwardedHost) != "" {
c.Request().Host = c.Request().Header.Get(echo.HeaderXForwardedHost)
Copy link
Contributor

@aldas aldas May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting host from proxied request is little bit more complex and has security nuances. Please see https://.com/labstack/echo/blob/master/ip.go

@aldas

NB: it is missing tests

@lammel

@padremortius Do you want to continue on this PR or shall we close it?

@padremortius

@lammel, yes. Added some changes and unit-test

@aldas

unit tests are only for scheme parsing. this is only small part of that middleware.


Currently it introduces new header "forwarded" RFC7239 which I think - if implemented should be integrated into c.RealIP() and IPExtractor code as well.

about RFC7239 and Go standard library golang/go#30963

maybe instead of that Regex we could have small parser that takes in header value, goes over that rune/char by rune/char and outputs parsed parts or an error. RFC7239 should not be that complex as spec is not that complex.

@padremortius

@aldas i'm added unit-test for method ProxyHeaders().

Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.