Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SkipClean to be evaluated on each route independently. #463

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gavbaa
Copy link

@gavbaa gavbaa commented Mar 21, 2019

This provides a solution to #460 . Cleaning is now moved into the route matcher, and is only activated if SkipClean has been set for that specific router (whether explicitly, or by inheritance from a parent route upon creation).

Note that due to the lack of parent knowledge in a Route/Router (which was removed a few months ago), SkipClean() changes only apply to routes that were created after the SkipClean change. Since we have no handle or reference to a Subrouter() once it's been created from the parent router (it's only stored as a matcher interface), we can't make SkipClean() trickle down to the already existing children. New ones will pick it up though. Since this is how other current properties behave, this seemed to be expected behavior.

@elithrar
Copy link
Contributor

elithrar commented Mar 21, 2019 via email

Copy link
Contributor

@elithrar elithrar left a comment

Choose a reason for hiding this comment

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

See comments.

Note the documentation - docstrings, README, etc - needs improvement. The burden of documentation on any PR over time grows as the API grows, else we risk making this library even harder to use / more confusing to newcomers.

@@ -413,6 +406,13 @@ type RouteMatch struct {
Handler http.Handler
Vars map[string]string

// Cleaned version of the path being matched.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these are exported, can you provide clearer guidance for a user trying to understand either:

  • What their value is?
  • Should I be setting this?
  • What the default is?

@@ -170,7 +171,23 @@ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
if r.options.useEncodedPath {
path = req.URL.EscapedPath()
}
return r.regexp.MatchString(path)
if !r.options.skipClean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document this code-path more clearly - e.g. "why".

@elithrar
Copy link
Contributor

Hey @gavbaa - are you still interested in finishing this one off?

@gavbaa
Copy link
Author

gavbaa commented Jul 5, 2019

Yes, just have to set some time aside to go through and address the comments.

@theverything
Copy link

Is there any way that I can help to get this merged? I need this!!

@fharding1
Copy link
Contributor

@theverything you could create your own branch and complete the remainder of the work if you'd like.

Copy link

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Started looking into this today and realised the documentation for SkipClean isn't correct at the moment, but this PR seems like it should fix that. Is there anything I can do to help get this PR across the finish line?

mux.go Outdated
Comment on lines 200 to 201
w.Header().Set("Location", url.String())
w.WriteHeader(http.StatusMovedPermanently)

Choose a reason for hiding this comment

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

Have you considered using http.Redirect here instead? Would be more consistent with what other projects are doing.
Basically the difference is that it would give a response body with the location in too and a moved permanently message.

@amustaque97
Copy link
Contributor

Hey @gavbaa, @theverything - are you guys working on this PR?

mux.go Outdated Show resolved Hide resolved
Co-authored-by: Jarri Abidi <jarri1337@gmail.com>
Signed-off-by: Corey Daley <cdaley@redhat.com>
@coreydaley
Copy link
Contributor

@gavbaa If you would like to resolve the conflict with this pull request we can work on getting it reviewed and merged. Thanks

@jaitaiwan
Copy link

Just noting no response as yet - will plan on coming back around to this if there's further updates.

@jaitaiwan jaitaiwan self-assigned this Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

None yet

9 participants