Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

route requests based on pattern or query parameters #22

Merged
merged 5 commits into from
Mar 24, 2020

Conversation

C0rby
Copy link
Contributor

@C0rby C0rby commented Mar 23, 2020

Closes #21

@C0rby C0rby requested review from IljaN and refs March 23, 2020 18:10
Copy link
Member

@refs refs left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

Set this to debug

Comment on lines 57 to 64
// 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
Copy link
Member

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

return false
}

func (p *MultiHostReverseProxy) regexRouteHandler(endpoint string, target url.URL) bool {
Copy link
Member

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 :)

return matched
}

func (p *MultiHostReverseProxy) prefixRouteHandler(endpoint string, target url.URL) bool {
Copy link
Member

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 (
Copy link
Member

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?

Copy link
Contributor Author

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",
Copy link
Member

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?

Copy link
Contributor Author

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?

Str("path", r.URL.Path).
Str("routeType", string(routeType)).
Msg("director found")
break
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok 👍

@C0rby C0rby merged commit 38fc0d2 into master Mar 24, 2020
@delete-merged-branch delete-merged-branch bot deleted the advanced-route-matching branch March 24, 2020 10:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Match routes based on query parameter or regex
2 participants