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

Route wildcards get confused with query params #1452

Closed
karinehovhannisyan opened this issue Mar 12, 2021 · 4 comments
Closed

Route wildcards get confused with query params #1452

karinehovhannisyan opened this issue Mar 12, 2021 · 4 comments

Comments

@karinehovhannisyan
Copy link

Hi, we lately faced a weird situation with wildcards and query params in Ocelot.

Expected Behavior

We would expect the wildcards to have no relation to anything that comes after the ? symbol and proceed the request as is.

Actual Behavior

If a route query parameter contains the value of the wildcard, its first symbol is truncated and the parameter name is changed.

Steps to Reproduce the Problem

Here is how we got this.

  1. Added a route like this (some fields are missing here)
{
    "DownstreamPathTemplate": "/api/{version}/Companies/{companyId}/all",
    "DownstreamScheme": "http",
    "DownstreamHostAndPorts": [
      {
        ...
      }
    ],
    "UpstreamPathTemplate": "/api/{version}/Companies/{companyId}/all",
    "UpstreamHttpMethod": [ "Get" ],
  }
  1. Make a request with this URL: http://localhost/api/v2/Companies/111/all?companyIds=111&companyIds=123
  2. Our downstream receives the following params:
  • ompanyIds - 111
  • companyIds - 123

I also tried to add the {everything} after the ?, but then if one makes a call like this:
http://localhost/api/v2/Companies/111/all/?companyIds=111&companyIds=123

They receive a 404 error.

Specifications

  • Version: 17.0.0
  • Platform: .NET 5 application
  • Subsystem:
@ghost
Copy link

ghost commented Mar 18, 2022

Hi I am also facing the same , can anyone help me?

@raman-m
Copy link
Member

raman-m commented Jan 19, 2024

It should be already fixed in v20.0
Are you interested in details?

@raman-m
Copy link
Member

raman-m commented Jan 28, 2024

Hi @karinehovhannisyan!
This is well-known bug and it was fixed in v20.0, see commit ae43f32 and PR #1182 plz.

You need to re-define upstream template as following:

{
    "DownstreamPathTemplate": "/api/{version}/Companies/{companyId}/all?{everything}",
    "UpstreamPathTemplate": "/api/{version}/Companies/{companyId}/all?{everything}",
}

See more here 👉

But...
Your both templates are identical! They are the same, no transformations, no changes at all.
In this case you can define one Catch All route:

{
    "DownstreamPathTemplate": "/{everything}",
    "UpstreamPathTemplate": "/{everything}",
}

It should route any URL with any query strings.

@raman-m
Copy link
Member

raman-m commented Jan 28, 2024

Already fixed by #1182

@raman-m raman-m closed this as completed Jan 28, 2024
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

No branches or pull requests

2 participants