Skip to content

Commit bcc83dd

Browse files
Do not return a body for no content responses (#644)
1 parent 9567601 commit bcc83dd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Modules/ReverseProxy/Provider/ReverseProxyProvider.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Globalization;
2+
using System.Net;
23
using System.Net.Http.Headers;
34
using System.Web;
45

@@ -154,7 +155,7 @@ private IResponseBuilder GetResponse(HttpResponseMessage response, IRequest requ
154155
}
155156
else
156157
{
157-
if (knownLength != null)
158+
if (request.HasType(RequestMethod.Head) && (knownLength != null))
158159
{
159160
builder.Length(knownLength.Value);
160161
}
@@ -211,7 +212,12 @@ private void SetHeaders(IResponseBuilder builder, IRequest request, HttpHeaders
211212

212213
private static bool CanSendBody(IRequest request) => !request.HasType(RequestMethod.Get, RequestMethod.Head, RequestMethod.Options);
213214

214-
private static bool HasBody(IRequest request, HttpResponseMessage response) => !request.HasType(RequestMethod.Head) && response.Content.Headers.ContentType is not null;
215+
private static bool HasBody(IRequest request, HttpResponseMessage response)
216+
{
217+
return !request.HasType(RequestMethod.Head)
218+
&& response.Content.Headers.ContentType is not null
219+
&& response.StatusCode != HttpStatusCode.NoContent;
220+
}
215221

216222
private string RewriteLocation(string location, IRequest request)
217223
{

0 commit comments

Comments
 (0)