krakend / krakend-ce

KrakenD Community Edition: High-performance, stateless, declarative, API Gateway written in Go.
https://www.krakend.io
Apache License 2.0
1.86k stars 443 forks source link

Path variable isn't propagated to backend properly if not enclosed by /. #856

Closed blankser closed 3 months ago

blankser commented 4 months ago

Environment info:

Describe the bug Path variable isn't propagated to backend properly if not enclosed by /. Its send as {{.A}} when a is the variable name. It should send the actual variable value that is captured from the url.

Your configuration file:

{
  "version": 3,
  "endpoints": [
{
      "endpoint": "/test/{a}test/{b}",
      "backend": [
        {
          "host": [
            "http://localhost:8080"
          ],
          "url_pattern": "/__debug/test/{a}test/{b}"          
        }
      ]
    }
]
}

Commands used

docker run --rm -it -p "8080:8080" --network="host" -v $PWD:/etc/krakend/ devopsfaith/krakend:2.5.0-watch run -d -c krakend.json

Expected behavior when calling curl http://localhost:8080/test/Xtest/Y I get in the log:

[00] [GIN] 2024/03/07 - 14:36:28 | 200 |      83.275µs |       127.0.0.1 | GET      "/__debug/test/{{.A}}test/Y"
[00] [GIN] 2024/03/07 - 14:36:28 | 200 |     816.334µs |       127.0.0.1 | GET      "/test/Xtest/Y"

I expect:

[00] [GIN] 2024/03/07 - 14:36:28 | 200 |      83.275µs |       127.0.0.1 | GET      "/__debug/test/Xtest/Y"
[00] [GIN] 2024/03/07 - 14:36:28 | 200 |     816.334µs |       127.0.0.1 | GET      "/test/Xtest/Y"

Logs see above

Additional context adding "disable_rest": true, to the config doesn't make a difference.

nsitbon commented 3 months ago

Hi @blankser you can't do that as Krakend relies internally on httprouter : a path param starts with : and ends with a / https://github.com/julienschmidt/httprouter/blob/master/tree.go#L43. Best regards

blankser commented 3 months ago

ok thanks for letting me know