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

I have some trouble on route match #3134

Closed
zhuliquan opened this issue Dec 27, 2020 · 7 comments · Fixed by #3154
Closed

I have some trouble on route match #3134

zhuliquan opened this issue Dec 27, 2020 · 7 comments · Fixed by #3154
Labels
checking check first if this issue occurred

Comments

@zhuliquan
Copy link

Issue description

I set two routes like this:
##route1
{"uris":["/test/v1/files/*"],"name":"get_file1","desc":"get_file1","methods":["GET"],"vars":[],"plugins":{"proxy-rewrite":{"regex_uri":["^/test/v1/files/(.+)","/v1/files/$1"]}},"upstream_id":"333773215308464216"}
##route2
{"uris":["/test/v1/files:listReputationHistories"],"name":"list_reputation_history1","methods":["POST"],"vars":[],"plugins":{"proxy-rewrite":{"uri":"/v1/files:listReputationHistories"}},"upstream_id":"333773215308464216"}

But run command: curl "http://127.0.0.1:9080/test/v1/files:xxxdsadsadxxx" -XPOST -d {"uri":"xxx"} , It also can return results.
APISIX sames to match '/test/v1/files:xxxdsadsadxxx' to '"/test/v1/files:listReputationHistories'. I also try other cases: curl "http://127.0.0.1:9080/test/v1/files: {any string}" -XPOST -d {"uri":"xxx"} , APISIX sames ignore string behind ':'.

Environment

  • apisix version (cmd: 2.1):
@Firstsawyou
Copy link
Contributor

Can you provide a minimal reproducible use case?

@juzhiyuan juzhiyuan added the checking check first if this issue occurred label Dec 27, 2020
@zhuliquan
Copy link
Author

zhuliquan commented Dec 27, 2020

GRPC service

I use grpc build service
protobuf:


import "google/api/annotations.proto";
package test_grpc.api.file;

option go_package = ".;file";

message Request {
  string uri = 1;
}

message Response {
  string info = 1;
}

service File {
  rpc GetFile (Request) returns (Response) {
    option (google.api.http) = {
      get: "/v1/{uri=files/*}"
    };
  }
  rpc ListReputationHistories (Request) returns (Response) {
    option (google.api.http) = {
      post: "/v1/files:listReputationHistories"
    };
  }
}

service code.

func (s *FileServerImpl) GetFile(ctx context.Context, r *file.Request) (*file.Response, error) {
        return &file.Response{Info: "GetFile:" + r.GetUri()}, nil
}
func (s *FileServerImpl) ListReputationHistories(ctx context.Context, r *file.Request) (*file.Response, error) {
        return &file.Response{Info: "ListReputationHistories:" + r.GetUri()}, nil
}

I run service with prot:9201, and use grpc-gateway provide http service.

APISIX

upstreams:

curl -XPUT "http://127.0.0.1:9080/apisix/admin/upstreams/1" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'  -d '{"nodes":{"host":"127.0.0.1:9201" : 1},  "type":"roundrobin", "name":"test_grpc_http"}'

routes:

curl -XPUT "http://127.0.0.1:9080/apisix/admin/routes/1" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d '{"uris":["/test/v1/files/*"],"name":"get_file1","methods":["GET"],"plugins":{"proxy-rewrite":{"regex_uri":["^/test/v1/files/(.+)","/v1/files/$1"]}},"upstream_id":"1"}'
curl -XPUT "http://127.0.0.1:9080/apisix/admin/routes/2" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d '{"uris":["/test/v1/files:listReputationHistories"],"name":"list_reputation_history1","methods":["POST"],"plugins":{"proxy-rewrite":{"uri":"/v1/files:listReputationHistories"}},"upstream_id":"1"}'

Fact

I send any post request with prefix /test/v1/files: , result is same with /test/v1/files:listReputationHistories
for example:
curl "http://127.0.0.1:9080/test/v1/files:esxxx" -XPOST -d {"uri":"xxx"}
{"info":"ListReputationHistories:"}(base)
截图20201227204059719

`

@Firstsawyou
Copy link
Contributor

The characters with : in the url here are very similar to the prefix path, right? @spacewander

@zhuliquan
Copy link
Author

zhuliquan commented Dec 28, 2020

The characters with : in the url here are very similar to the prefix path, right? @spacewander

Yes, /test/v1/files:/test/v1/files:listReputationHistories and /test/v1/files:xxxxxxx will return same results, even I don't define route with /test/v1/files:xxxxxxx. APISIX ignore characters behind ':' , only match string "/test/v1/files" before ':'

@tokers
Copy link
Contributor

tokers commented Dec 28, 2020

See https://github.com/api7/lua-resty-radixtree#parameters-in-path, : in the Route of APISIX has special meanings.

@spacewander
Copy link
Member

We need to fix it in lua-resty-radixtree. ":" is legal in uri and is recommended in RESTful API by Google: https://cloud.google.com/apis/design/custom_methods

@spacewander
Copy link
Member

Added as api7/lua-resty-radixtree#82

spacewander added a commit to spacewander/incubator-apisix that referenced this issue Dec 29, 2020
Fix apache#3134.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
spacewander added a commit to spacewander/incubator-apisix that referenced this issue Dec 29, 2020
Fix apache#3134.

You can still get the original behavior by set
enable_parameter_in_route to true.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
spacewander added a commit to spacewander/incubator-apisix that referenced this issue Dec 30, 2020
Fix apache#3134.

You can still get the original behavior by using
radixtree_uri_with_parameter router.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checking check first if this issue occurred
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants