Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove msgtype requirement in HttpMessageContent #407

Open
jods4 opened this issue Jul 25, 2023 · 1 comment
Open

Remove msgtype requirement in HttpMessageContent #407

jods4 opened this issue Jul 25, 2023 · 1 comment
Milestone

Comments

@jods4
Copy link

jods4 commented Jul 25, 2023

HttpMessageContent serializes HTTP requests/responses inside a mulitpart/mixed body.

For requests, it sends the header Content-Type: application/http; msgtype=request.
For responses, it expects the header Content-Type: application/http; msgtype=response.

This is where msgtype=request is added in source:

Headers.ContentType.Parameters.Add(new NameValueHeaderValue(MsgTypeParameter, DefaultRequestMsgType));

This is where msgtype=response is validated in source:

foreach (NameValueHeaderValue parameter in contentType.Parameters)
{
if (parameter.Name.Equals(MsgTypeParameter, StringComparison.OrdinalIgnoreCase))
{
string msgType = FormattingUtilities.UnquoteToken(parameter.Value);
if (!msgType.Equals(isRequest ? DefaultRequestMsgType : DefaultResponseMsgType, StringComparison.OrdinalIgnoreCase))
{
if (throwOnError)
{
throw Error.Argument("content", Properties.Resources.HttpMessageInvalidMediaType, FormattingUtilities.HttpContentType.Name, isRequest ? DefaultRequestMediaType : DefaultResponseMediaType);
}
else
{
return false;
}
}
return true;
}
}
}
if (throwOnError)
{
throw Error.Argument("content", Properties.Resources.HttpMessageInvalidMediaType, FormattingUtilities.HttpContentType.Name, isRequest ? DefaultRequestMediaType : DefaultResponseMediaType);
}
else
{
return false;
}

HttpMessageContent should be configurable to not sent a msgtype parameter, and accept responses without a msgtype (given Content-Type: application/http).

As a common real-world example, the OData specification uses Content-Type: application/http without any further msgtype in both its batched requests and responses, see:
https://www.odata.org/documentation/odata-version-2-0/batch-processing/

Inside Microsoft, Dataverse exposes OData services and its batching endpoint is unusable with HttpMessageContent because:

  • Dataverse throws when a batch has msgtype=request in its Content-Type;
  • ReadAsHttpResponseMessageAsync() throws when parsing Dataverse response because it does not have msgtype=response.
@MackinnonBuck
Copy link
Member

Thanks for reaching out. We are currently prioritizing critical bug fixes and security issues over new features in this repository. Putting this in the backlog to collect more feedback.

@MackinnonBuck MackinnonBuck added this to the Backlog milestone Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants