-
Notifications
You must be signed in to change notification settings - Fork 17
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
add regular expression matching to --output-http-rewrite-url #127
Conversation
Hi! Thank you for this change! But i think it will not be full without allowing to use matched parts in resulting url, for example:
So you can use regexp with match groups on left side, and use them on right side. |
I have now switched to ReplaceAllString and tested with the modified url of 2014-10-28 15:10 GMT+01:00 Leonid Bugaev notifications@github.com:
|
t.Error("Should not error on /v1/user/([^\\/]+)/ping:/v2/user/$1/ping") | ||
} | ||
|
||
url = "/v1/user/joe/ping" |
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.
Pls also add tests that explicitly checks if rewrites.Rewrite(url) == /v2/user/joe/ping
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.
pushed. does that work for you?
2014-10-28 18:24 GMT+01:00 Leonid Bugaev notifications@github.com:
In settings_url_map_test.go:
@@ -25,3 +24,24 @@ func TestUrlRewriteMap(t *testing.T) {
t.Error("Request url should not have been rewritten, was")
}
}
+
+func TestUrlRewriteMap_2(t *testing.T) {
- var url string
- rewrites := UrlRewriteMap{}
- err := rewrites.Set("/v1/user/([^\/]+)/ping:/v2/user/$1/ping")
- if err != nil {
t.Error("Should not error on /v1/user/([^\/]+)/ping:/v2/user/$1/ping")
- }
- url = "/v1/user/joe/ping"
Pls also add tests that explicitly checks if rewrites.Rewrite(url) ==
/v2/user/joe/ping—
Reply to this email directly or view it on GitHub
https://github.com/buger/gor/pull/127/files#r19487611.
Thanks! Looks great! I will review it one more time tomorrow and will merge. |
if f.src == path { | ||
return f.target | ||
if f.src.MatchString(path) { | ||
return f.src.ReplaceAllString(path, f.target) |
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.
Did not know about ReplaceAllString function, love go standard lib! :)
add regular expression matching to --output-http-rewrite-url
Please add this small patch, it fixes multiple occurrences in the same path
|
Done eb7885c! Thanks for pointing. |
I extended --output-http-rewrite-url to also accept regular expressions for matching.