-
Notifications
You must be signed in to change notification settings - Fork 2
route requests based on pattern or query parameters #22
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 , minimal changes
if handler(endpoint, *r.URL) { | ||
p.Director = p.Directors[policy][routeType][endpoint] | ||
hit = true | ||
p.logger. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set this to debug
pkg/config/config.go
Outdated
// PrefixRoute are routes matched by a prefix | ||
PrefixRoute RouteType = "Prefix" | ||
// QueryRoute are routes machted by a prefix and query parameters | ||
QueryRoute RouteType = "Query" | ||
// RegexRoute are routes matched by a pattern | ||
RegexRoute RouteType = "Regex" | ||
// DefaultRouteType is the PrefixRoute | ||
DefaultRouteType RouteType = PrefixRoute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the string to be lowercase? like:
PrefixRoute RouteType = "prefix"
// QueryRoute are routes machted by a prefix and query parameters
QueryRoute RouteType = "query"
// RegexRoute are routes matched by a pattern
RegexRoute RouteType = "regex"
// DefaultRouteType is the PrefixRoute
DefaultRouteType RouteType = PrefixRoute
pkg/proxy/proxy.go
Outdated
return false | ||
} | ||
|
||
func (p *MultiHostReverseProxy) regexRouteHandler(endpoint string, target url.URL) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go for Matcher
instead of Handler, as you said :)
pkg/proxy/proxy.go
Outdated
return matched | ||
} | ||
|
||
func (p *MultiHostReverseProxy) prefixRouteHandler(endpoint string, target url.URL) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, Matcher
DefaultRouteType RouteType = PrefixRoute | ||
) | ||
|
||
var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be a const and added to the const block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, Golang currently doesn't support constant arrays.
@@ -154,6 +211,11 @@ func defaultPolicies() []config.Policy { | |||
Endpoint: "/ocs/", | |||
Backend: "http://localhost:9140", | |||
}, | |||
config.Route{ | |||
Type: config.QueryRoute, | |||
Endpoint: "/remote.php/?preview=1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could type Route
, instead of defining the query string as part of the endpoint and potentially getting cluttered, have a matcher
or regexp
field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That opens one problem I had.
How do I get the value? Currently the structure only holds information about the endpoint and the type. If we would replace the endpoint with the route than how could we efficiently retrieve the default route?
pkg/proxy/proxy.go
Outdated
Str("path", r.URL.Path). | ||
Str("routeType", string(routeType)). | ||
Msg("director found") | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only break the inner loop. Could we use a label in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outer loop checks if !hit
but in case of a match we set hit to true so it will exit the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aah, too mystical. Still think a label is easier to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok 👍
Closes #21