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

Rewrite by verb 1130 #1187

Merged
merged 3 commits into from
May 22, 2020
Merged

Rewrite by verb 1130 #1187

merged 3 commits into from
May 22, 2020

Conversation

pimg
Copy link
Contributor

@pimg pimg commented Apr 27, 2020

This resolves #1130 by taking an array of HTTP methods in the config for either the commands or the query_args_command. When the one or HTTP methods are applied in the config the rewrite rule only executes if the request method matches one in the config. If no methods are provided in the config the rewrite command will execute on all request methods.

@pimg pimg requested a review from a team as a code owner April 27, 2020 13:01
@eloycoto
Copy link
Contributor

Hi @pimg

Thanks for your contribution. Have been super busy days here, I'll review this policy asap, but I do not forget it.

Regards

Copy link
Contributor

@eloycoto eloycoto left a comment

Choose a reason for hiding this comment

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

Just a few minor comments, but overall looks awesome! Thanks!

@@ -107,6 +144,57 @@
],
"default": "plain"
}
},
"methods": {
Copy link
Contributor

Choose a reason for hiding this comment

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

It'll be nice if a new definition for methods can be done, we're trying to implement that because make things easier to follow and less verbose. As a example:
https://github.com/3scale/APIcast/blob/master/gateway/src/apicast/policy/jwt_claim_check/apicast-policy.json#L13

Reference
https://json-schema.org/understanding-json-schema/structuring.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

-- Returns true if no Method is provided in the config for backwardscompatibility
local function should_apply(methods)
local request_method = ngx.req.get_method()
local next = next
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this next to the top of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


local should_apply_command = true

if methods ~= nil and next(methods) ~= nil then
Copy link
Contributor

Choose a reason for hiding this comment

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

This code can be a bit simpler, what about:

local function should_apply(methods)
  local request_method = ngx.req.get_method()

  if methods == nil and next(methods) == nil  then
    return true
  end

  for _,v in pairs(methods) do
    if v == request_method then
      return true
    end
  end
  return false
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Eloy thanks for the review comments, I'm working to resolve them.
One question: should't if methods == nil and next(methods) == nil then
be: if methods == nil or next(methods) == nil then
(So or instead of and) because in the case of and when methods == nil next(methods) will throw an error? Or am I missing something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rest is changed

@@ -28,6 +28,30 @@ local function substitute(func, subject, regex, replace, options)
return new_uri, num_changes > 0
end

-- Returns true if the Method of the request is in the methods of the command meaning the rewrite rule should be applied
-- Returns true if no Method is provided in the config for backwardscompatibility
local function should_apply(methods)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about if we change the function name to is_match_method(methods)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

pimg and others added 3 commits May 22, 2020 16:53
…d and refactored should_apply method to is_match_method
Signed-off-by: Eloy Coto <eloy.coto@acalustra.com>
@eloycoto eloycoto merged commit 65f8882 into 3scale:master May 22, 2020
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.

Re-write rules determined by HTTP Verb
2 participants