Change FormValueProviderFactory to use GetContentType for media type matching

Fixes #68
This commit is contained in:
Pranav K 2014-03-20 21:01:07 -07:00
parent 1ca2203421
commit f1c4a8e497
5 changed files with 13 additions and 18 deletions

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.ModelBinding.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {

View File

@ -1,12 +1,7 @@
using System; 
using System.Collections.Generic; namespace Microsoft.AspNet.Mvc.ModelBinding
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc.ModelBinding.Internal
{ {
public class ContentTypeHeaderValue internal class ContentTypeHeaderValue
{ {
public ContentTypeHeaderValue([NotNull] string contentType, public ContentTypeHeaderValue([NotNull] string contentType,
string charSet) string charSet)
@ -18,6 +13,5 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal
public string ContentType { get; private set; } public string ContentType { get; private set; }
public string CharSet { get; set; } public string CharSet { get; set; }
} }
} }

View File

@ -1,9 +1,9 @@
using System; using System;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Mvc.ModelBinding.Internal namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
public static class HttpRequestExtensions internal static class HttpRequestExtensions
{ {
private const string ContentTypeHeader = "Content-Type"; private const string ContentTypeHeader = "Content-Type";
private const string CharSetToken = "charset="; private const string CharSetToken = "charset=";

View File

@ -25,9 +25,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private bool IsSupportedContentType(HttpRequest request) private bool IsSupportedContentType(HttpRequest request)
{ {
var contentType = request.Headers["Content-Type"]; var contentType = request.GetContentType();
return !String.IsNullOrEmpty(contentType) && return contentType != null &&
contentType.Equals(FormEncodedContentType, StringComparison.OrdinalIgnoreCase); contentType.ContentType.Equals(FormEncodedContentType, StringComparison.OrdinalIgnoreCase);
} }
private static CultureInfo GetCultureInfo(HttpRequest request) private static CultureInfo GetCultureInfo(HttpRequest request)

View File

@ -24,11 +24,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
Assert.Null(result); Assert.Null(result);
} }
[Fact] [Theory]
public async Task GetValueProvider_ReturnsValueProviderInstaceWithInvariantCulture() [InlineData("application/x-www-form-urlencoded")]
[InlineData("application/x-www-form-urlencoded;charset=utf-8")]
public async Task GetValueProvider_ReturnsValueProviderInstaceWithInvariantCulture(string contentType)
{ {
// Arrange // Arrange
var requestContext = CreateRequestContext("application/x-www-form-urlencoded"); var requestContext = CreateRequestContext(contentType);
var factory = new FormValueProviderFactory(); var factory = new FormValueProviderFactory();
// Act // Act