Removed Content Type header for response when no content is being returned (#8557)
Addresses #8230
This commit is contained in:
parent
b743ba2f66
commit
aa89639d62
|
|
@ -52,10 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(result));
|
throw new ArgumentNullException(nameof(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
SetContentType(context, result);
|
|
||||||
SetContentDispositionHeader(context, result);
|
|
||||||
|
|
||||||
var request = context.HttpContext.Request;
|
var request = context.HttpContext.Request;
|
||||||
var httpRequestHeaders = request.GetTypedHeaders();
|
var httpRequestHeaders = request.GetTypedHeaders();
|
||||||
|
|
||||||
|
|
@ -83,6 +80,9 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
return (range: null, rangeLength: 0, serveBody: false);
|
return (range: null, rangeLength: 0, serveBody: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetContentType(context, result);
|
||||||
|
SetContentDispositionHeader(context, result);
|
||||||
|
|
||||||
if (fileLength.HasValue)
|
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
|
// Assuming the request is not a range request, and the response body is not empty, the Content-Length header is set to
|
||||||
|
|
|
||||||
|
|
@ -444,6 +444,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var body = streamReader.ReadToEndAsync().Result;
|
var body = streamReader.ReadToEndAsync().Result;
|
||||||
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
|
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
|
||||||
Assert.Null(httpResponse.ContentLength);
|
Assert.Null(httpResponse.ContentLength);
|
||||||
|
Assert.False(httpResponse.Headers.ContainsKey(HeaderNames.ContentType));
|
||||||
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
|
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
|
||||||
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
|
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
|
||||||
Assert.Empty(body);
|
Assert.Empty(body);
|
||||||
|
|
|
||||||
|
|
@ -432,10 +432,11 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
var httpResponse = actionContext.HttpContext.Response;
|
var httpResponse = actionContext.HttpContext.Response;
|
||||||
httpResponse.Body.Seek(0, SeekOrigin.Begin);
|
httpResponse.Body.Seek(0, SeekOrigin.Begin);
|
||||||
var streamReader = new StreamReader(httpResponse.Body);
|
var streamReader = new StreamReader(httpResponse.Body);
|
||||||
var body = streamReader.ReadToEndAsync().Result;
|
var body = await streamReader.ReadToEndAsync();
|
||||||
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
|
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
|
||||||
Assert.Null(httpResponse.ContentLength);
|
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.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
|
||||||
Assert.Empty(body);
|
Assert.Empty(body);
|
||||||
Assert.False(readStream.CanSeek);
|
Assert.False(readStream.CanSeek);
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
Assert.Null(httpResponse.ContentLength);
|
Assert.Null(httpResponse.ContentLength);
|
||||||
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
|
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
|
||||||
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
|
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
|
||||||
|
Assert.False(httpResponse.Headers.ContainsKey(HeaderNames.ContentType));
|
||||||
Assert.Empty(body);
|
Assert.Empty(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -402,6 +402,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
Assert.Null(httpResponse.ContentLength);
|
Assert.Null(httpResponse.ContentLength);
|
||||||
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
|
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
|
||||||
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
|
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
|
||||||
|
Assert.False(httpResponse.Headers.ContainsKey(HeaderNames.ContentType));
|
||||||
Assert.Empty(body);
|
Assert.Empty(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue