parent
0989231ed5
commit
ce8fc29728
|
|
@ -10,8 +10,6 @@ using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using Microsoft.AspNetCore.Mvc.Internal;
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.Routing;
|
|
||||||
using Microsoft.AspNetCore.Routing;
|
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
using Resources = Microsoft.AspNetCore.Mvc.Core.Resources;
|
using Resources = Microsoft.AspNetCore.Mvc.Core.Resources;
|
||||||
|
|
||||||
|
|
@ -79,7 +77,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
|
|
||||||
// Confirm the request's content type is more specific than a media type this action supports e.g. OK
|
// Confirm the request's content type is more specific than a media type this action supports e.g. OK
|
||||||
// if client sent "text/plain" data and this action supports "text/*".
|
// if client sent "text/plain" data and this action supports "text/*".
|
||||||
if (requestContentType != null && !IsSubsetOfAnyContentType(requestContentType))
|
if (requestContentType == null || !IsSubsetOfAnyContentType(requestContentType))
|
||||||
{
|
{
|
||||||
context.Result = new UnsupportedMediaTypeResult();
|
context.Result = new UnsupportedMediaTypeResult();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("")]
|
[InlineData("")]
|
||||||
[InlineData(null)]
|
[InlineData(null)]
|
||||||
public void OnResourceExecuting_NullOrEmptyRequestContentType_IsNoOp(string contentType)
|
public void OnResourceExecuting_NullOrEmptyRequestContentType_SetsUnsupportedMediaTypeResult(string contentType)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var httpContext = new DefaultHttpContext();
|
var httpContext = new DefaultHttpContext();
|
||||||
|
|
@ -349,7 +349,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
consumesFilter.OnResourceExecuting(resourceExecutingContext);
|
consumesFilter.OnResourceExecuting(resourceExecutingContext);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Null(resourceExecutingContext.Result);
|
Assert.NotNull(resourceExecutingContext.Result);
|
||||||
|
Assert.IsType<UnsupportedMediaTypeResult>(resourceExecutingContext.Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -30,22 +29,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
|
|
||||||
Assert.True(result);
|
Assert.True(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The endpoint routing version of this feature has fixed https://github.com/aspnet/Mvc/issues/8174
|
|
||||||
[Fact]
|
|
||||||
public override async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var request = new HttpRequestMessage(
|
|
||||||
HttpMethod.Post,
|
|
||||||
"http://localhost/ConsumesAttribute_PassThrough/CreateProduct");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var response = await Client.SendAsync(request);
|
|
||||||
var body = await response.Content.ReadAsStringAsync();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(HttpStatusCode.UnsupportedMediaType, response.StatusCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public virtual async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent()
|
public async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent_ReturnsUnsupported()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var request = new HttpRequestMessage(
|
var request = new HttpRequestMessage(
|
||||||
|
|
@ -58,11 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await Client.SendAsync(request);
|
var response = await Client.SendAsync(request);
|
||||||
var body = await response.Content.ReadAsStringAsync();
|
await response.AssertStatusCodeAsync(HttpStatusCode.UnsupportedMediaType);
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
||||||
Assert.Equal("ConsumesAttribute_PassThrough_Product_Json", body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue