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

feat: add support for header based route #565

Merged
merged 7 commits into from
Jul 2, 2023

Conversation

shawnh2
Copy link
Contributor

@shawnh2 shawnh2 commented Jun 4, 2023

Add support for header based route.

  • when use it alone in a route, it has the higher priority to be matched in a router

@ma642 ma642 requested review from ma642 and mark4z June 4, 2023 12:17
pixiu/pkg/common/router/router.go Show resolved Hide resolved
@mark4z
Copy link
Member

mark4z commented Jun 11, 2023

考虑扩展下现有的samples来演示如何使用header路由

@mark4z
Copy link
Member

mark4z commented Jun 11, 2023

Good job!

@shawnh2
Copy link
Contributor Author

shawnh2 commented Jun 16, 2023

考虑扩展下现有的samples来演示如何使用header路由

sample has been added, apache/dubbo-go-pixiu-samples#30

@codecov-commenter
Copy link

Codecov Report

Merging #565 (9288b90) into develop (613998a) will increase coverage by 0.02%.
The diff coverage is 66.66%.

❗ Current head 9288b90 differs from pull request most recent head d009c5f. Consider uploading reports for the commit d009c5f to get more accurate results

@@             Coverage Diff             @@
##           develop     #565      +/-   ##
===========================================
+ Coverage    54.76%   54.79%   +0.02%     
===========================================
  Files          669      669              
  Lines        78297    78331      +34     
===========================================
+ Hits         42882    42918      +36     
- Misses       31756    31757       +1     
+ Partials      3659     3656       -3     
Impacted Files Coverage Δ
pixiu/pkg/server/http.go 0.00% <0.00%> (ø)
pixiu/pkg/router/route.go 45.73% <50.00%> (ø)
pixiu/pkg/common/router/trie/trie.go 72.30% <55.17%> (-3.11%) ⬇️
pixiu/pkg/common/router/router.go 82.19% <84.00%> (+13.56%) ⬆️

... and 15 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@AlexStocks
Copy link
Contributor

@yqxu review this pr

@sonarcloud
Copy link

sonarcloud bot commented Jun 29, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
1.7% 1.7% Duplication

@@ -75,22 +75,83 @@ func NewRouterMatchPrefix(name string) RouterMatch {
return RouterMatch{Prefix: "/" + name + "/"}
}

func (rc *RouteConfiguration) RouteByPathAndMethod(path, method string) (*RouteAction, error) {
func (rc *RouteConfiguration) RouteByPathAndMethod(path, method string, header stdHttp.Header) (*RouteAction, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The behavior of a method should be reflected in its name. It is recommended to modify the name as RouteByPathAndMethodAndHeader.

@@ -317,7 +339,7 @@ func (node *Node) putPathVariable(pathVariable string, isReal bool, bizInfo inte
return true
}

func (node *Node) putNode(matchStr string, isReal bool, bizInfo interface{}) bool {
func (node *Node) putNode(matchStr string, isReal bool, bizInfo interface{}, header map[string][]string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

The "header" should be an attribute of "bizInfo".

@@ -333,13 +355,14 @@ func (node *Node) putNode(matchStr string, isReal bool, bizInfo interface{}) boo

if isReal {
selfNode.bizInfo = bizInfo
selfNode.header = header
Copy link
Contributor

Choose a reason for hiding this comment

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

The "header" should be an attribute of "bizInfo".

@AlexStocks AlexStocks merged commit f498fe5 into apache:develop Jul 2, 2023
13 checks passed
@mark4z mark4z added this to the v1.0.0 milestone Aug 27, 2023
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