Azure / azure-relay-bridge

Azure Relay Bridge - A cross-platform command line tool to create VPN-less TCP tunnels from and to anywhere
MIT License
121 stars 48 forks source link

TcpRemoteForwarder HTTP path throws FormatException on content-type with parameters #91

Closed clemensv closed 2 months ago

clemensv commented 2 months ago

FormatException thrown when a content-type with parameters is used. Error occurs with in "CreateHttpRequestMessage" where the content-type header is added.

Minimal repro of the code path:

using System.Net.Http.Headers;
using System.Net.Mime;

var requestMessage = new HttpRequestMessage();
requestMessage.Content = new StreamContent(new MemoryStream());
var contentType = "application/cloudevents+json; charset=utf-8";
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);

If you drop the "charset" clause, it succeeds. The use of the MediaTypeHeaderValue constructor is incorrect here because it requires a media type as input and not a content-type.