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

add new filter of redirector to do redirect of 3xx #883

Merged
merged 5 commits into from
Dec 27, 2022

Conversation

suchen-sci
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2022

Codecov Report

Base: 76.10% // Head: 75.83% // Decreases project coverage by -0.27% ⚠️

Coverage data is based on head (1fa3f77) compared to base (4c9b3a1).
Patch coverage: 69.23% of modified lines in pull request are covered.

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     
Impacted Files Coverage Δ
pkg/filters/redirector/redirector.go 69.23% <69.23%> (ø)
pkg/object/mqttproxy/topic.go 47.05% <0.00%> (-52.95%) ⬇️
pkg/object/mqttproxy/session.go 67.70% <0.00%> (-14.51%) ⬇️
pkg/object/mqttproxy/client.go 77.45% <0.00%> (-4.16%) ⬇️
pkg/filters/validator/basicauth.go 76.53% <0.00%> (-2.27%) ⬇️
pkg/filters/headerlookup/headerlookup.go 84.61% <0.00%> (-1.40%) ⬇️
pkg/object/mqttproxy/broker.go 73.90% <0.00%> (-0.90%) ⬇️
pkg/object/mqttproxy/spec.go 100.00% <0.00%> (ø)
pkg/object/mqttproxy/mqttproxy.go 46.83% <0.00%> (ø)
pkg/object/mqttproxy/nocachetopicmgr.go 92.85% <0.00%> (ø)
... and 8 more

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

pkg/filters/redirector/redirector.go Outdated Show resolved Hide resolved
pkg/filters/redirector/redirector.go Outdated Show resolved Hide resolved
pkg/filters/redirector/redirector.go Outdated Show resolved Hide resolved
pkg/filters/redirector/redirector.go Outdated Show resolved Hide resolved
pkg/filters/redirector/redirector_test.go Show resolved Hide resolved
@suchen-sci suchen-sci changed the title add new filter of redirector to do redirect of 301 or 302 add new filter of redirector to do redirect of 3xx Dec 27, 2022
Copy link
Contributor

@haoel haoel left a 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.

pkg/filters/redirector/redirector.go Outdated Show resolved Hide resolved
pkg/filters/redirector/redirector.go Show resolved Hide resolved
pkg/filters/redirector/redirector.go Outdated Show resolved Hide resolved
pkg/filters/redirector/redirector.go Outdated Show resolved Hide resolved
@suchen-sci suchen-sci merged commit 234d91b into easegress-io:main Dec 27, 2022
@suchen-sci suchen-sci deleted the add-redirector branch December 27, 2022 10:30
}
}

func (r *Redirector) updateResponse(resp *httpprot.Response, matchResult string) {
Copy link
Collaborator

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`

Comment on lines +147 to +148
if !ok {
resp.SetPayload([]byte(statusCodeMap[301]))
Copy link
Collaborator

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)
Copy link
Collaborator

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 ""
Copy link
Collaborator

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
Copy link
Collaborator

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.

Comment on lines +116 to +119
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
}
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants