twitchax / AspNetCore.Proxy

ASP.NET Core Proxies made easy.
MIT License
505 stars 80 forks source link

DELETE request with body does not include body in proxied request #112

Open gjhommersom opened 8 months ago

gjhommersom commented 8 months ago

I have a 3th party service that uses the body of a DELETE to include additional data.

This library however does not include the body in the request it therefor fails with a 415 error. Issue is at https://github.com/twitchax/AspNetCore.Proxy/blob/b3f70afb1164c7d0e3658630fc7e7033a0080e70/src/Core/Extensions/Http.cs#L83

This is reproducible when sending the request directly to the 3th party service.

Is it possible that this gets fixed and the body is included?

twitchax commented 8 months ago

Yes, interesting issue.

However, I am not sure on the best fix. In practice, even though it is not strictly forbidden, it is generally accepted that the body of a DELETE should be ignored.

The best solution may be to allow someone to override the default?

gjhommersom commented 8 months ago

For now I have managed to create workaround that does the job.

.WithBeforeSend((context, request) =>
{
   if (request.Method == HttpMethod.Delete)
   {
       request.Content = new StreamContent(context.Request.Body);
       request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(context.Request.ContentType);
       request.Content.Headers.ContentLength = context.Request.ContentLength;
   }
   return Task.CompletedTask;
})