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

request_path match order #2242

Closed
zono opened this issue Mar 23, 2017 · 5 comments
Closed

request_path match order #2242

zono opened this issue Mar 23, 2017 · 5 comments

Comments

@zono
Copy link

zono commented Mar 23, 2017

I have some api endpoints and I want enable plugin on specific endpoint. I'm wondering how request_path matching works.

Take for the following example, I have two api settings; "api-item" and "api-all". I want to setup hmac plugin for only "api-item".

e.g. my expectation

GET http://api.sample.com/v1/items <= HMAC enabled
GET http://api.sample.com/v1/items/001 <= HMAC enabled
POST http://api.sample.com/v1/items <= HMAC enabled
GET http://api.sample.com/v1/employees <= HMAC disabled
GET http://api.sample.com/v1/customers <= HMAC disabled

After testing, it worked as my expectation. I think request_path priorities longer match. Is this my understanding correct?

* API List

curl -i -X GET \
  --url http://localhost:8001/apis/

{
  "data": [
    {
      "upstream_url": "http://api.sample.com/",
      "request_path": "/v1/items",
      "id": "6ac62668-09b6-4182-bee0-0cc5cb5d8d0d",
      "created_at": 1490233548000,
      "preserve_host": false,
      "strip_request_path": false,
      "name": "api-item"
    },
    {
      "upstream_url": "http://api.sample.com/",
      "request_path": "/v1",
      "id": "eb55641b-56f5-43a9-b976-9f912d850a41",
      "created_at": 1490234676000,
      "preserve_host": false,
      "strip_request_path": false,
      "name": "api-all"
    }
  ],
  "total": 2
}

* Plugin

curl -i -X GET \
    --url http://localhost:8001/apis/api-item/plugins/ \
    --data "name=hmac-auth"

{
  "api_id": "6ac62668-09b6-4182-bee0-0cc5cb5d8d0d",
  "id": "16eb69e3-14c8-41d2-a104-7f50b03ac1bb",
  "created_at": 1490233737000,
  "enabled": true,
  "name": "hmac-auth",
  "config": {
    "hide_credentials": false,
    "clock_skew": 300
  }
}
@zono
Copy link
Author

zono commented Mar 23, 2017

I searched keyword 'request_path' on the github repo but I couldn't find the source code of the matching process. I would be grateful if you can share the code so that I can see the process.

@therealgambo
Copy link

therealgambo commented Mar 23, 2017

This PR #1970 documents the way the selection is done for versions >= 0.10.0.

Also documentation around this can be found here: https://getkong.org/docs/0.10.x/proxy/#routing-priorities

@zono
Copy link
Author

zono commented Mar 23, 2017

Thank you. I'm reading it now.
My kong is now version 0.9.9.

@zono
Copy link
Author

zono commented Mar 23, 2017

The rule is that : when evaluating a request, Kong will first try to match the APIs with the most rules.
https://getkong.org/docs/0.10.x/proxy/#routing-priorities

It seems my understanding is correct. And I think that combining request_path and request_host became possible from version 0.10. Awesome. #845

@Tieske
Copy link
Member

Tieske commented Mar 24, 2017

before 0.10 the paths would be matched longest to shortest. So you are correct. In 0.10 it was rewritten, haven't checked, but assume that it still works the same way.

In general: the more specific match has a higher precedence

@Tieske Tieske closed this as completed Mar 24, 2017
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

No branches or pull requests

3 participants