Ocelot icon indicating copy to clipboard operation
Ocelot copied to clipboard

HEAD warning about hostname could not be parsed

Open mejsin opened this issue 4 years ago • 5 comments

Actual Behavior / Motivation for New Feature

see this warning: warn: Ocelot.Request.Middleware.DownstreamRequestInitialiserMiddleware[0] requestId: 0HLV2RDUF49SO:00000001, previousRequestId: no previous request id, message: Error when parsing incoming request, exception: System.UriFormatException: Invalid URI: The hostname could not be parsed. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at Ocelot.Request.Mapper.RequestMapper.Map(HttpRequest request, DownstreamReRoute downstreamReRoute)

a bunch of times in log, can I solve this issue or should I just ignore it and if then can I setup to ignore this error so it does not come to log ?

Steps to Reproduce the Problem

  1. We have a route: { "DownstreamPathTemplate": "/{everything}", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "${PORTAL_API_HOST}", "Port": ${PORTAL_API_PORT} } ], "UpstreamPathTemplate": "/{everything}", "UpstreamHttpMethod": [ "GET", "POST","PUT","HEAD" ] }

Specifications

  • Version:14.0.11
  • Platform: linux
  • Subsystem:

mejsin avatar Apr 17 '20 15:04 mejsin

Hi

Any updates on this?

mejsin avatar Aug 18 '20 16:08 mejsin

Hi,

I am facing the same issue. Did you find any solution?

yashadsingh avatar Aug 30 '20 11:08 yashadsingh

Hi, Sorry no, and still no answer on this...

mejsin avatar Aug 31 '20 06:08 mejsin

Hello,

Im coming from the future. After 2 years the problem wont be fixed. ;d I have it too : (

zontak avatar Aug 15 '22 19:08 zontak

Hi All,

First time using Ocelot so don't judge my silly mistake, I had this same error but in my case it simply came down to the port setup, hope this helps someone:

Incorrect DownstreamHostAndPorts: "DownstreamHostAndPorts": [ { "Host": "localhost:7178", "Port": 443 } ]

Correct DownstreamHostAndPorts:

"DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 7178 } ],

As you can see, the error simply came down to the double inclusion of the ports which resulted in an invalid URI "localhost:7178:443".

Cheers

clodewyks avatar Sep 19 '22 18:09 clodewyks

@mejsin

1

          "Host": "${PORTAL_API_HOST}",
          "Port": "${PORTAL_API_PORT}"

2

System.UriFormatException: Invalid URI: The hostname could not be parsed.

Conclusion

You can't use in-place placeholders of strange format, because Ocelot doesn't support them! You must pre-process your template file by a script and replace placeholders with correct values :exclamation:

raman-m avatar Mar 23 '24 16:03 raman-m

Misconfiguration issue and invalid route definition!

raman-m avatar Mar 23 '24 16:03 raman-m