8000 Problem with redirect path /some/path/ to /some/path inside kong instance · Issue #14630 · Kong/kong · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Problem with redirect path /some/path/ to /some/path inside kong instance #14630
Open
@witold-gren

Description

@witold-gren

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

Kong 3.9

Current Behavior

Hi, I have some problems with not supported path which at the end contains /. But when I create request to the same path without slash everything works correctly. I started looking for a way to fix it and had a few ideas.

  1. Adding the following configuration to the kong configuration:
    nginx_proxy_rewrite: "^/(.*)/$ /$1"
    however, although the appropriate entry is generated (/kong_prefix/nginx-kong.conf):
server {
    rewrite: ^/(.*)/$ /$1
}

this solution did not work. (I have not noticed any changes in the operation of the kong)

  1. Try to create custom plugin:
handler.lua: |
  local kong = kong
                
  local plugin = {
      PRIORITY = 778,
      VERSION = "1.0"
  }
  ...
  function plugin:access(plugin_conf)
    local path = ngx.re.sub(ngx.var.uri, "^/(.*)/$", "/$1", "o")
    ...
    kong.service.request.set_path(path)
    ...

but it also not works. (In this case, the plugin is executed after the routing has been determined, so creating a request with a slash at the end ot path will return a 404 response)

  1. I found a pre-function plugin that allows you to run your own plugin before processing the query. I also prepared a configuration for it..
...
config:
  rewrite:
  - |2
    local uri = ngx.re.sub(ngx.var.uri, "^/(.*)/$", "/$1", "o")
    if uri ~= ngx.var.uri then
      kong.service.request.set_path(uri)
      ngx.req.set_uri(uri, true)
    end

but also in this case it does not work correctly. (In the last case, there is a redirection, but kong in the kong.request.get_path() variable has the original path with a slash and also in this case returns a 404 response)

What else can I do to make kong support both types of url paths?

  • /some/path
  • /some/path/

Expected Behavior

I think that in each of the above cases the traffic should be redirected to a non-slash path and kong should be able to handle it.

Steps To Reproduce

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending author feedbackWaiting for the issue author to get back to a maintainer with findings, more details, etc...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0