core/config: add support for stripping the port for matching routes (#5085)

* core/config: add support for stripping the port for matching routes

* fix test

* rename option, improve port detection

* add more test cases
This commit is contained in:
Caleb Doxsey 2024-04-26 08:24:46 -06:00 committed by GitHub
parent 498c3aa108
commit 5373e25ac4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 100 additions and 34 deletions

View file

@ -613,14 +613,14 @@ func (p *Policy) String() string {
}
// Matches returns true if the policy would match the given URL.
func (p *Policy) Matches(requestURL url.URL) bool {
func (p *Policy) Matches(requestURL url.URL, stripPort bool) bool {
// an invalid from URL should not match anything
fromURL, err := urlutil.ParseAndValidateURL(p.From)
if err != nil {
return false
}
if !FromURLMatchesRequestURL(fromURL, &requestURL) {
if !FromURLMatchesRequestURL(fromURL, &requestURL, stripPort) {
return false
}