Ocelot: Use of non ASCII characters in the header

Created on 29 Jan 2019  路  5Comments  路  Source: ThreeMammals/Ocelot

Expected Behavior

Use of non ASCII characters in the header of a http request, for example 帽.

Actual Behavior

I鈥檓 getting these exceptions:

HttpRequesterMiddleware

  warn: Ocelot.Requester.Middleware.HttpRequesterMiddleware[0] 

  requestId: 0HLK5V6HTDSH7:00000001, previousRequestId: no previous request id, message: Error making http request, exception: System.Net.Http.HttpRequestException: Request headers must contain only ASCII characters. 

     at System.Net.Http.HttpConnection.WriteStringAsync(String s) 

     at System.Net.Http.HttpConnection.WriteHeadersAsync(HttpHeaders headers, String cookiesFromContainer) 

     at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) 

     at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) 

     at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) 

     at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task'1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) 

     at Ocelot.Requester.HttpClientHttpRequester.GetResponse(DownstreamContext context)`

ResponderMiddleware:

  warn: Ocelot.Responder.Middleware.ResponderMiddleware[0] 

  requestId: 0HLK5V6HTDSH7:00000001, previousRequestId: no previous request id, message: Error Code: UnableToCompleteRequestError Message: Error making http request, exception: System.Net.Http.HttpRequestException: Request headers must contain only ASCII characters. 

     at System.Net.Http.HttpConnection.WriteStringAsync(String s) 

     at System.Net.Http.HttpConnection.WriteHeadersAsync(HttpHeaders headers, String cookiesFromContainer) 

     at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) 

     at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) 

     at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) 

     at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task'1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) 

     at Ocelot.Requester.HttpClientHttpRequester.GetResponse(DownstreamContext context) errors found in ResponderMiddleware. Setting error response for request path:/api/v1/Products, request method: POST`

Steps to Reproduce the Problem

  1. Add a header with a non ASCII character.

Specifications

  • Version: 13.0.0

  • Platform: Windows 10 x64

Most helpful comment

the latest .net core 2.2 support non-ascii characters, we hope ocelot can support too!!!!

All 5 comments

This has nothing to do with ocelot, the http standard defines that only ASCII characters are valid in the headers. Closing.

Are you sure it only supports ASCII?

The HTTP header field values may contain characters other than ASCII characters:
https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
https://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2

Maybe the standard leaves a door open for anothers encoding, but as the exception says, net core only allows headers encoded as ascii. Until they don't change the framework we can't do anything from our side. Sorry

the latest .net core 2.2 support non-ascii characters, we hope ocelot can support too!!!!

the latest .net core 2.2 support non-ascii characters, we hope ocelot can support too!!!!

Do you have a reference for this? I am getting the same error as OP with .net core 2.2 and am having trouble finding anything confirming your statement.

Was this page helpful?
0 / 5 - 0 ratings