Removed Content Type header for response when no content is being returned (#8557)

Addresses #8230
This commit is contained in:
Chirag Rupani 2019-03-21 01:45:42 +05:30 committed by Pranav K
parent b743ba2f66
commit aa89639d62
5 changed files with 10 additions and 6 deletions

View File

@ -52,10 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
{
throw new ArgumentNullException(nameof(result));
}
SetContentType(context, result);
SetContentDispositionHeader(context, result);
var request = context.HttpContext.Request;
var httpRequestHeaders = request.GetTypedHeaders();
@ -83,6 +80,9 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
return (range: null, rangeLength: 0, serveBody: false);
}
SetContentType(context, result);
SetContentDispositionHeader(context, result);
if (fileLength.HasValue)
{
// Assuming the request is not a range request, and the response body is not empty, the Content-Length header is set to

View File

@ -444,6 +444,7 @@ namespace Microsoft.AspNetCore.Mvc
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
Assert.Null(httpResponse.ContentLength);
Assert.False(httpResponse.Headers.ContainsKey(HeaderNames.ContentType));
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);

View File

@ -432,10 +432,11 @@ namespace Microsoft.AspNetCore.Mvc
var httpResponse = actionContext.HttpContext.Response;
httpResponse.Body.Seek(0, SeekOrigin.Begin);
var streamReader = new StreamReader(httpResponse.Body);
var body = streamReader.ReadToEndAsync().Result;
var body = await streamReader.ReadToEndAsync();
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.False(httpResponse.Headers.ContainsKey(HeaderNames.ContentType));
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Assert.False(readStream.CanSeek);

View File

@ -305,6 +305,7 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.False(httpResponse.Headers.ContainsKey(HeaderNames.ContentType));
Assert.Empty(body);
}

View File

@ -402,6 +402,7 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.False(httpResponse.Headers.ContainsKey(HeaderNames.ContentType));
Assert.Empty(body);
}