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

[feature] Path Resolver #282

Merged
merged 5 commits into from
Jun 3, 2015
Merged

[feature] Path Resolver #282

merged 5 commits into from
Jun 3, 2015

Conversation

thibaultcha
Copy link
Member

First implementation of #192. After discussions, it was decided to implement a basic working version of the Path resolver but a version that introduces changes that goes towards the end-goal of supporting all discussed features of #192.

Changes
  • An API must have at least a public_dns or a path.
  • An API can have both.
  • An API is limited to 1 public_dns and 1 path for now (we can have several at the same time later, but it'll require a heavy data migration as discussed in [request] support for routing based on path? #192).
  • Upon receiving a request, Kong will load all the APIs in the system (cached for 60 seconds), and try to find a public_dns matching either the Host or X-Host-Override header. If nothing was found yet, it tries to compare the request_uri with the path currently in memory. Hence, public_dns has the priority over path.
Example:
$ curl --url http://localhost:8001/apis \
    -d "name=mockbin" \
    -d "path=/status/" \
    -d "target_url=http://mockbin.com"
201
$ curl --url http://localhost:8000/status/200
{
  "code": "200",
  "message": "OK"
}
Improvements:
  • Implement a strip_path option so that /status/200 will actually resolve to target_url/200.
  • Implement a coroutine that automatically reloads the APIs in memory every 60 seconds instead of waiting for a request to query it.
  • Check path is alphanumeric only.
  • After 0.3.0: eventually support multiple public_dns and path (this means supporting priority and regex for paths).

@sonicaghi
Copy link
Member

@DavidTPate let us know if you have suggestion or feedback before we merge it. thanks.

@thibaultcha thibaultcha added pr/wip A work in progress PR opened to receive feedback NEEDS REVIEW labels Jun 2, 2015
-- Otherwise, we look for it by path. We have to loop over all APIs and compare the requested URI.
local request_uri = ngx.var.request_uri
for path, api in pairs(apis_dics.path) do
local m, err = ngx.re.match(request_uri, path)

Choose a reason for hiding this comment

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

It's been awhile since I've done LUA, but it looks like path when stored in the database would be something like /status where the / would be added if not present to the beginning but the regular expression matching here doesn't check where /status is.

What it looks like to me is that if I created an API with the path /status when it gets to the comparison point it would compile the regular expression to /\/status/ (where / is my boundary character). Which means that it will match a request to /myapi/status, /status, /something/status/somethingelse/status etc. I'm not sure how you want to approach it, but Express in NodeJS land for example uses a few configuration parameters to create their Regular Expression. You can see those in path-to-regexp under the options section.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR is not 100% finished, and I was thinking to simply match if the request_uri starts with the path. It's a good start and good enough for this implementation (one path per API).

I originally wanted path to be an actual regex users could set, but I think it's better to do like I just described first, and implement multiple paths and regex at the same time.

Choose a reason for hiding this comment

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

Definitely agree, first out simply pre-pending $ to the path would be good before doing the match.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you mean ^?

Choose a reason for hiding this comment

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

Hahaha. Yeah, sorry it's been a long day.

@DavidTPate
Copy link

@sinzone Looks good to me, the only blocking issue I saw was my comments about pre-pending the path with ^ to make sure it is matching the beginning of the request_uri not anywhere within the URL and it sounds like @thibaultcha already has a plan for that.

Thanks for the quick turnaround everyone!

@thibaultcha
Copy link
Member Author

👍

@ahmadnassri
Copy link
Contributor

@DavidTPate thanks for the detailed feedback!

@thibaultcha thibaultcha force-pushed the feature/path-resolver branch from c4e2435 to ac267b8 Compare June 2, 2015 15:49
@thibaultcha
Copy link
Member Author

The last 2 commits implement:

  • A check for path value as suggested by @DavidTPate. It checks the path is made of the unreserved characters list of RFC 3986.
  • Implement the strip_path option as suggested in the original issue.

@thibaultcha thibaultcha added pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) and removed pr/wip A work in progress PR opened to receive feedback NEEDS REVIEW labels Jun 2, 2015
@thibaultcha thibaultcha force-pushed the feature/path-resolver branch from d39b830 to feb7259 Compare June 3, 2015 13:23
- APIs now expect either a `public_dns` or a `path`.
- some schemas improvements on consumers and apis
- rename the newest migration to 0.3.0, the new kong version
- Check that a path complies to unreserved RFC 3986 characters
- Only match a path in the resolver if the request_uri *starts* with it
@thibaultcha thibaultcha force-pushed the feature/path-resolver branch from feb7259 to 5228fb2 Compare June 3, 2015 17:01
thibaultcha added a commit that referenced this pull request Jun 3, 2015
@thibaultcha thibaultcha merged commit 73e2eb4 into master Jun 3, 2015
@thibaultcha thibaultcha deleted the feature/path-resolver branch June 3, 2015 17:01
@sonicaghi
Copy link
Member

@DavidTPate we've released 0.3.1 - pls let us know if you have any feedback. thx! https://github.com/Mashape/kong/releases/tag/0.3.1

ctranxuan pushed a commit to streamdataio/kong that referenced this pull request Aug 25, 2015
[feature] Path Resolver

Former-commit-id: e22da6d567657810c0dcaa54380b3277c1864685
hutchic added a commit that referenced this pull request Jun 10, 2022
chore(go-pluginserver) small fix for go-pluginserver --version
bungle added a commit that referenced this pull request Mar 23, 2023
### Summary

The 0.17.0 is not beta anymore as the 0.17.1 was released as non-beta,
so lets start pinning the resty.http again.

#### What's Changed

Documentation is clearer about using same connection for multiple requests via 'request' function by @alexdowad in #282

- fix 100 response with headers by @catbro666
- fix: no trailing \"?\" for empty query table by @StarlightIbuki

#### New Contributors

@chronolaw made their first contribution
@alexdowad made their first contribution
@catbro666 made their first contribution
@StarlightIbuki made their first contribution

Signed-off-by: Aapo Talvensaari <[email protected]>
bungle added a commit that referenced this pull request Mar 23, 2023
### Summary

The 0.17.0 is not beta anymore as the 0.17.1 was released as non-beta,
so lets start pinning the resty.http again.

#### What's Changed

Documentation is clearer about using same connection for multiple requests via 'request' function by @alexdowad in #282

- fix 100 response with headers by @catbro666
- fix: no trailing \"?\" for empty query table by @StarlightIbuki

#### New Contributors

@chronolaw made their first contribution
@alexdowad made their first contribution
@catbro666 made their first contribution
@StarlightIbuki made their first contribution

Signed-off-by: Aapo Talvensaari <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants