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

Routing question: placeholders vs slash #658

Open
skyflyer opened this issue Oct 11, 2018 · 5 comments · May be fixed by #1333
Open

Routing question: placeholders vs slash #658

skyflyer opened this issue Oct 11, 2018 · 5 comments · May be fixed by #1333
Assignees
Labels
accepted Bug or feature would be accepted as a PR or is being worked on bug Identified as a potential bug

Comments

@skyflyer
Copy link

Expected Behavior

  • Request to /api/ would go to / downstream
  • Request to /api/test would go to /test downstream

Actual Behavior / Motivation for New Feature

  • Reqeust to /api/ is not resolved (see error below)
  • Request to /api/test goes to downstream `/test

Steps to Reproduce the Problem

  1. Have something listening on localhost:8000
  2. Configure ocelot to listen on localhost:5000
  3. Use config below

Config:

{
    "ReRoutes": [
        {
            "DownstreamPathTemplate": "/{everything}",
            "DownstreamScheme": "http",
            "DownstreamHostAndPorts": [
                {
                    "Host": "localhost",
                    "Port": 8000
                }
            ],
            "UpstreamPathTemplate": "/api/{everything}",
            "UpstreamHttpMethod": [
                "GET",
                "POST"
            ]
        }
    ],
    "GlobalConfiguration": {
        "BaseUrl": "http://localhost:5000"
    }
}

Specifications

  • Version: 12.0.1
  • Platform: mac
  • Subsystem: ?

Comments

It is interesting to note, that if I configure ReRoute as /{everything} -> /{everything}, then it works, so it seems to me that {everything} wildcard match is not consistent in theese two cases.

@TomPallister
Copy link
Member

@skyflyer

Request to /api/ would go to / downstream

This doesn't work because /{everything} expects something after the slash, you need a reroute that is just /

Request to /api/test goes to downstream `/test

Not sure if this is a typo? I assume it's working?

@TomPallister TomPallister added the question Initially seen a question could become a new feature or bug or closed ;) label Oct 13, 2018
@skyflyer
Copy link
Author

So here is what is puzzling me (it is unexpected).

Scenario 1

Config 1
{
    "ReRoutes": [
        {
            "DownstreamPathTemplate": "/{everything}",
            "DownstreamScheme": "http",
            "DownstreamHostAndPorts": [
                {
                    "Host": "localhost",
                    "Port": 8000
                }
            ],
            "UpstreamPathTemplate": "/{everything}",
            "UpstreamHttpMethod": [
                "GET",
                "POST"
            ],
            "RateLimitOptions": {
                "EnableRateLimiting": true,
                "ClientWhiteList": [],
                "Period": "1s",
                "Limit": 1,
                "PeriodTimespan": 5
            }
        }
    ],
    "GlobalConfiguration": {
        "BaseUrl": "http://localhost:5000",
        "RateLimitOptions": {
            "DisableRateLimitHeaders": false,
            "QuotaExceededMessage": "Over limit",
            "HttpStatusCode": 429
          }
    }
}

Config1, where I configure that everything coming to ocelot, goes to localhost:8000 works. So here, the pattern is /{everything} and it matches even / and also /ocelot.json and all works as one would expect.

Scenario 2

Config2
{
    "ReRoutes": [
        {
            "DownstreamPathTemplate": "/{everything}",
            "DownstreamScheme": "http",
            "DownstreamHostAndPorts": [
                {
                    "Host": "localhost",
                    "Port": 8000
                }
            ],
            "UpstreamPathTemplate": "/api/{everything}",
            "UpstreamHttpMethod": [
                "GET",
                "POST"
            ],
            "RateLimitOptions": {
                "EnableRateLimiting": true,
                "ClientWhiteList": [],
                "Period": "1s",
                "Limit": 1,
                "PeriodTimespan": 5
            }
        }
    ],
    "GlobalConfiguration": {
        "BaseUrl": "http://localhost:5000",
        "RateLimitOptions": {
            "DisableRateLimitHeaders": false,
            "QuotaExceededMessage": "Over limit",
            "HttpStatusCode": 429
          }
    }
}

Based on the Config1, I would expect similar behaviour, only it is not, and I believe it should be (at least based on my experience with Apache and Nginx proxy setttings.

Are you saying that if I want to achieve that, I would need to configure two ReRoutes? One for /api/ and one for /api/{everything}?

@TomPallister
Copy link
Member

@skyflyer yeh i think I might be wrong. This probably should work the way you expect but I don't know why it doesnt :/ I will mark this as a bug and see if we can get a fix!

@TomPallister TomPallister added bug Identified as a potential bug and removed question Initially seen a question could become a new feature or bug or closed ;) labels Oct 21, 2018
@philproctor philproctor added the help wanted Not actively being worked on. If you plan to contribute, please drop a note. label Jan 9, 2019
@raman-m raman-m added accepted Bug or feature would be accepted as a PR or is being worked on and removed help wanted Not actively being worked on. If you plan to contribute, please drop a note. labels Aug 5, 2023
@raman-m raman-m changed the title ReRouting question Routing question: placeholders vs slash Aug 5, 2023
@raman-m
Copy link
Member

raman-m commented Aug 5, 2023

@raman-m
Copy link
Member

raman-m commented Aug 14, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Bug or feature would be accepted as a PR or is being worked on bug Identified as a potential bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants