Skip to content

How to configure Ocelot to prevent it from adding the port to my downstream URL? #1692

Closed

Description

@walissonde

Hello,
I am currently working on a Proof of Concept (POC) using Ocelot, but I have encountered an issue when making a URL call from localhost to route traffic to my API.
Is that correct when missing downstream port is replaced with an upstream port?

Actual Behavior

The base URL of my project is:

  • Host: localhost
  • Port: 5021

I also have a downstream URL, for instance:

  • Downstream URL: my-external-api.com (without specifying any port)

However, when I make a call to my URL through the Ocelot gateway, it adds a port to my URL, causing my external API to malfunction because it doesn't expect a port.

Here's what happens:

I call my upstream URL as follows: localhost:5021/gateway/my-api
Ocelot attempts to call my downstream and adds a port: my-external-api.com:5021

Expected Behavior

Now, I'm looking for a way to configure Ocelot to ignore this added port (e.g., 5021) when making calls to my API. I've already removed the port from my downstream configuration.

How can I configure Ocelot to resolve this issue and prevent it from adding the port to my downstream URL?

Specifications

  • Version: 19.0.2
  • Platform: .NET 7
  • Subsystem: Windows

Activity

  1. changed the title [-]Route from Localt to URL without PORT[/-] [+]Route from Localhost to URL without PORT[/+] on Sep 12, 2023
  2. raman-m commented on Sep 15, 2023

    @raman-m
    Member

    Hi Walisson!
    Thanks for your interest in Ocelot!

    As far as I understood, Ocelot substitutes downstream port by upstream port when there is no downstream port. Correct?
    If Yes, it can be a bug. But this scenario should be reproduced and proved.
    Also, you need to check Ocelot logs for a warnings & messages of configuration validation.
    Could you check your logs for messages please?

    On my opinion, when there is no specified downstream port, so a warning should be logged.
    Moreover, as a default feature, missing port must be initialized by default port of current scheme (protocol) like:

    • http: 80
    • https: 443
    • ws: ?
    • etc.
  3. raman-m commented on Sep 15, 2023

    @raman-m
    Member

    How can I configure Ocelot to resolve this issue and prevent it from adding the port to my downstream URL?

    Just define the downstream port for all routes! For example:

    {
      "Routes": [
        {
          // Route 1
          "DownstreamScheme": "http",
          "DownstreamHostAndPorts": [
            {
              "Host": "route1.com",
              "Port": 80
            }
          ],
          // ...
        },
        {
          // Route 2
          "DownstreamScheme": "https",
          "DownstreamHostAndPorts": [
            {
              "Host": "route2.com",
              "Port": 443
            }
          ],
          // ...
        },
      ],
      "GlobalConfiguration": {
      }
    }

    Let me know testing results please!

  4. added
    question
    waiting
    on Sep 15, 2023
  5. changed the title [-]Route from Localhost to URL without PORT[/-] [+]Missing downstream port is replaced with an upstream port[/+] on Sep 15, 2023
  6. raman-m commented on Oct 9, 2023

    @raman-m
    Member

    @walissonde commented on Sep 13

    Answering your question

    How can I configure Ocelot to resolve this issue and prevent it from adding the port to my downstream URL?

    I suggested you just specify Port value explicitly as is done for all routes now as the default behavior.

    Regarding potential bug of port substitution from upstream... Still need to check it... Haven't you received validation errors 7 warning in the log?

    Also, I've looked into the code, the DownstreamRequestCreator class, and it has no extra logic related to Port property.
    The Port property has no implicit initializations...
    Historically Port should be initialized explicitly in configuration of the Route, because downstream services have deployed behind firewalls which open access with specific ports.


    Have I answered on your question?
    Would you like to convert your question to bug/feature type?

  7. raman-m commented on Oct 9, 2023

    @raman-m
    Member

    @walissonde It could be a bug, it can be a feature, I'm not sure now. Historically all routes should have specified port.
    So, moving this thread to discussions...

  8. removed
    waiting
    on Oct 19, 2023
  9. changed the title [-]Missing downstream port is replaced with an upstream port[/-] [+]How to configure Ocelot to prevent it from adding the port to my downstream URL?[/+] on Oct 19, 2023
  10. locked and limited conversation to collaborators on Oct 19, 2023
  11. converted this issue into a discussion #1750 on Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions