-
Notifications
You must be signed in to change notification settings - Fork 494
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 new filter of redirector to do redirect of 3xx #883
Conversation
4c58737
to
8400674
Compare
Codecov ReportBase: 76.10% // Head: 75.83% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #883 +/- ##
==========================================
- Coverage 76.10% 75.83% -0.28%
==========================================
Files 110 115 +5
Lines 12698 13452 +754
==========================================
+ Hits 9664 10201 +537
- Misses 2490 2675 +185
- Partials 544 576 +32
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
just have two additional comments.
} | ||
} | ||
|
||
func (r *Redirector) updateResponse(resp *httpprot.Response, matchResult string) { |
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.
matchResult
is not a good name here, better use something like 'newLocation`
if !ok { | ||
resp.SetPayload([]byte(statusCodeMap[301])) |
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.
it seems this case is impossible, please remove it.
func (r *Redirector) Handle(ctx *context.Context) string { | ||
req := ctx.GetInputRequest().(*httpprot.Request) | ||
matchInput := r.getMatchInput(req) | ||
matchResult := r.re.ReplaceAllString(matchInput, r.spec.Replacement) |
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.
what happens if matchInput
does not match the regular expression?
resp, _ := httpprot.NewResponse(nil) | ||
r.updateResponse(resp, matchResult) | ||
ctx.SetOutputResponse(resp) | ||
return "" |
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 return value should be 'redirected'.
filters.BaseSpec `json:",inline"` | ||
|
||
Match string `json:"match" jsonschema:"required"` | ||
MatchPart string `json:"matchPart" jsonschema:"required,enum=uri|full|path"` // default uri |
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.
propose to improve the name matchPart
, as match
is a regular expression, it seems we don't need to distinguish uri
and path
.
if _, ok := statusCodeMap[r.spec.StatusCode]; !ok { | ||
logger.Errorf("invalid status code of Redirector, support 300, 301, 302, 303, 304, 307, 308, use 301 instead") | ||
r.spec.StatusCode = 301 | ||
} |
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.
these checks should be done in 'Spec.Validate`.
} | ||
|
||
if r.spec.MatchPart == "" { | ||
r.spec.MatchPart = matchPartURI |
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 should be done in kind.DefaultSpec
No description provided.