Skip to content

Empty placeholders: Failed to match Route configuration for upstream path #748

@satano

Description

@satano

Expected Behavior

Match upstream path with empty placeholder and map it correctly to downstream.

Actual Behavior / Motivation for New Feature

Upstream path with placeholder is not working as expected when placeholder is empty. It fails with error:

UnableToFindDownstreamRouteError Message: Failed to match ReRoute configuration for upstream path: /test

Steps to Reproduce the Problem

This special catch all configuration of ReRoute works as expected

"DownstreamPathTemplate": "/api/invoices/{url}"
"UpstreamPathTemplate": "/{url}"

It maps URLs this way:

/ → /api/invoices/
/123 → /api/invoices/123

Now this mapping (downstream is the same):

"DownstreamPathTemplate": "/api/invoices/{url}"
"UpstreamPathTemplate": "/test/{url}"

It works correctly when {url} is specified: /test/123 → /api/invoices/123

But it fails, when {url} is empty. I would expect upstream URL /test/ to reroute to downstream URL /api/invoices/. The error is:

dbug: Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware[0]
      requestId: 0HLJQAG2RQPKO:00000005, previousRequestId: no previous request id, message: Upstream url path is /test/
warn: Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware[0]
      requestId: 0HLJQAG2RQPKO:00000005, previousRequestId: no previous request id, message: DownstreamRouteFinderMiddleware setting pipeline errors. IDownstreamRouteFinder returned Error Code: UnableToFindDownstreamRouteError Message: Failed to match ReRoute configuration for upstream path: /test/, verb: GET.
warn: Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware[0]
      requestId: 0HLJQAG2RQPKO:00000005, previousRequestId: no previous request id, message: Failed to match ReRoute configuration for upstream path: /test/, verb: GET.
warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
      requestId: 0HLJQAG2RQPKO:00000005, previousRequestId: no previous request id, message: Error Code: UnableToFindDownstreamRouteError Message: Failed to match ReRoute configuration for upstream path: /test/, verb: GET. errors found in ResponderMiddleware. Setting error response for request path:/test/, request method: GET
dbug: Ocelot.Errors.Middleware.ExceptionHandlerMiddleware[0]
      requestId: 0HLJQAG2RQPKO:00000005, previousRequestId: no previous request id, message: ocelot pipeline finished

As a special case of this, I would also expect routing to ignore trailing slash, because from WEB/API wiew, usually the address with the slash at the end is the same as without it. So upstream URL /test would map to downstream URL /api/invoices. Maybe this is not exact from the computers point of view, but for me it makes sense from human point of view of configuration. It does not work this way even if the routing is configured without the slashes:

"DownstreamPathTemplate": "/api/invoices{url}"
"UpstreamPathTemplate": "/test{url}"

It correctly maps non epmty {url} which means, it works with the slash at the end, because the slash is the value of the {url}. But still not without it:

/test/123 → /api/invoices/123
/test/ → /api/invoices/
/test → Failed to match ReRoute configuration for upstream path: /test

To make work everything what I want, I need three reroutes (or at least two, if the first one will be without slashes):

{
    "DownstreamPathTemplate": "/api/invoices/{url}"
    "UpstreamPathTemplate": "/test/{url}"
},
{
    "DownstreamPathTemplate": "/api/invoices/"
    "UpstreamPathTemplate": "/test/"
},
{
    "DownstreamPathTemplate": "/api/invoices"
    "UpstreamPathTemplate": "/test"
}

Specifications

  • Version: Ocelot 13.0.0
  • Platform: .NET Core 2.2 on Windows

Metadata

Metadata

Assignees

Labels

Nov'23November 2023 releasebugIdentified as a potential bugmergedIssue has been merged to dev and is waiting for the next release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions