You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to configure Ocelot to prevent it from adding the port to my downstream URL? #1692
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?
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:
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?
@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...
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
Activity
[-]Route from Localt to URL without PORT[/-][+]Route from Localhost to URL without PORT[/+]raman-m commentedon Sep 15, 2023
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:
raman-m commentedon Sep 15, 2023
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!
[-]Route from Localhost to URL without PORT[/-][+]Missing downstream port is replaced with an upstream port[/+]raman-m commentedon Oct 9, 2023
Answering your question
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
Portproperty.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?
raman-m commentedon Oct 9, 2023
@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...
[-]Missing downstream port is replaced with an upstream port[/-][+]How to configure Ocelot to prevent it from adding the port to my downstream URL?[/+]