parent
0989231ed5
commit
ce8fc29728
|
|
@ -10,8 +10,6 @@ using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
|||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
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
|
||||
// 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
public void OnResourceExecuting_NullOrEmptyRequestContentType_IsNoOp(string contentType)
|
||||
public void OnResourceExecuting_NullOrEmptyRequestContentType_SetsUnsupportedMediaTypeResult(string contentType)
|
||||
{
|
||||
// Arrange
|
||||
var httpContext = new DefaultHttpContext();
|
||||
|
|
@ -349,7 +349,8 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
consumesFilter.OnResourceExecuting(resourceExecutingContext);
|
||||
|
||||
// Assert
|
||||
Assert.Null(resourceExecutingContext.Result);
|
||||
Assert.NotNull(resourceExecutingContext.Result);
|
||||
Assert.IsType<UnsupportedMediaTypeResult>(resourceExecutingContext.Result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
|
|
@ -30,22 +29,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
|
||||
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]
|
||||
public virtual async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent()
|
||||
public async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent_ReturnsUnsupported()
|
||||
{
|
||||
// Arrange
|
||||
var request = new HttpRequestMessage(
|
||||
|
|
@ -58,11 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
|
||||
// Act
|
||||
var response = await Client.SendAsync(request);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("ConsumesAttribute_PassThrough_Product_Json", body);
|
||||
await response.AssertStatusCodeAsync(HttpStatusCode.UnsupportedMediaType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
|
|||
Loading…
Reference in New Issue