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(plugin) Adding path prefix support in request transformer #1426

Closed

Conversation

andyfleming
Copy link

Summary

Allows for a path prefix to be prepended or removed.

So with the following configuration...

curl -X POST http://localhost:8001/apis/mockbin/plugins \
  --data "name=request-transformer" \
  --data "config.remove.path_prefix[1]=/example" \
  --data "config.add.path_prefix[1]=/another"

A request to /example/page would be transformed to /another/page

NOTE: I have not set up a full dev environment, so I have not actually tested these changes.

If someone could take a look, I think the changes are pretty straightforward.

Full changelog

  • Implemented path prefix support
  • Created test

Issues resolved

May address #724

@andyfleming andyfleming changed the title Adding path prefix transformation support feat(plugin) Adding path prefix support in request transformer Jul 19, 2016
(was based on the old master branch style instead of new next styles)
if (stringy.startswith(uri, value)) then
uri = uri:sub(value:len() + 1)
if (uri:substr(0, value:len()) == value) then
uri = uri:substr(value:len() + 1)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be sub instead of substr? does this even work...

Copy link
Author

Choose a reason for hiding this comment

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

Oops, typo. Good catch! Thanks! Updated in 99b3a63.

@Tieske
Copy link
Member

Tieske commented Jul 19, 2016

I think xx-api_spec.lua could use some input validation tests, with at a minimum a check on;

  • starts with a slash
  • does not end with a slash
  • valid characters for path (incl. %-encoded)

@andyfleming
Copy link
Author

@Tieske — I'm not completely following. What are the specific expectations you have in mind? Are you talking about upon API routing? or setting the plugin settings?

@Tieske
Copy link
Member

Tieske commented Jul 22, 2016

@andyfleming apologies for not being clear. I meant the plugin settings.

@andyfleming
Copy link
Author

@Tieske No worries. Is there another file I can look at that has similar tests to use as a starting point?

@Tieske
Copy link
Member

Tieske commented Aug 15, 2016

have a look at the existing request-tranformer api specs; https://github.com/Mashape/kong/blob/next/spec/03-plugins/13-request-transformer/02-api_spec.lua

just extend that file with the new tests

@Tieske
Copy link
Member

Tieske commented Aug 15, 2016

and this is the existing code for checking a path; https://github.com/Mashape/kong/blob/next/kong/dao/schemas/apis.lua#L76-L109

@andyfleming
Copy link
Author

It looks like my use case is actually already covered by strip_request_path. I misinterpreted the documentation.

I'm going to close this. If someone else later wants to pursue this functionality, they are welcome to run with it.

@andyfleming andyfleming closed this Sep 8, 2016
@Tieske Tieske mentioned this pull request Nov 27, 2016
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.

3 participants