Error: FormatException: The format of value 'application/json; charset=utf-8' is invalid.
sasank-chaganty opened this issue · 1 comments
Hello,
I've been encountering a persistent issue where if I get a request with the following header sent to my relay endpoint:
Content-Type
: application/json; charset=utf-8
azbridge prints out the following error:
Error: FormatException: The format of value 'application/json; charset=utf-8' is invalid.
Adding more detail for this issue:
Error: System.FormatException: 'The format of value 'application/json; charset=utf-8' is invalid.'
This exception was originally thrown at this call stack:
System.Net.Http.Headers.MediaTypeHeaderValue.CheckMediaTypeFormat(string, string)
System.Net.Http.Headers.MediaTypeHeaderValue.MediaTypeHeaderValue(string)
Microsoft.Azure.Relay.Bridge.TcpRemoteForwarder.CreateHttpRequestMessage(Microsoft.Azure.Relay.RelayedHttpListenerContext) in TcpRemoteForwarder.cs
Microsoft.Azure.Relay.Bridge.TcpRemoteForwarder.HandleRequest(Microsoft.Azure.Relay.RelayedHttpListenerContext) in TcpRemoteForwarder.cs
Failing on this line when contentType
is application/json; charset=utf-8
. For some reason, the MediaTypeHeaderValue
throws an error even though the string is RFC 2616 compliant
Looks like this has been a long-standing issue: dotnet/runtime#20272
Ended up using this work-around from @wjrogers to get unblocked:
var mediaType = MediaTypeHeaderValue.Parse("text/plain; charset=iso-8859-5");