React to string[] -> StringValues changes.

This commit is contained in:
Chris R 2015-08-28 16:36:19 -07:00
parent a2d58ba4ea
commit f2db0d1483
64 changed files with 241 additions and 356 deletions

View File

@ -385,26 +385,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </param> /// </param>
public void SetModelValue([NotNull] string key, ValueProviderResult valueProviderResult) public void SetModelValue([NotNull] string key, ValueProviderResult valueProviderResult)
{ {
// Avoid creating a new array for rawvalue if there's only one value. // Avoid creating a new array for rawValue if there's only one value.
object rawValue; object rawValue;
if (valueProviderResult == ValueProviderResult.None) if (valueProviderResult == ValueProviderResult.None)
{ {
rawValue = null; rawValue = null;
} }
else if (valueProviderResult.Value != null)
{
rawValue = valueProviderResult.Value;
}
else if (valueProviderResult.Length == 1) else if (valueProviderResult.Length == 1)
{ {
rawValue = valueProviderResult.Values[0]; rawValue = valueProviderResult.Values[0];
} }
else else
{ {
rawValue = valueProviderResult.Values; rawValue = valueProviderResult.Values.ToArray();
} }
SetModelValue(key, rawValue, (string)valueProviderResult); SetModelValue(key, rawValue, valueProviderResult.ToString());
} }
/// <summary> /// <summary>

View File

@ -4,9 +4,8 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -38,9 +37,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <summary> /// <summary>
/// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>. /// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>.
/// </summary> /// </summary>
/// <param name="value">The submitted value.</param> /// <param name="values">The submitted values.</param>
public ValueProviderResult(string value) public ValueProviderResult(StringValues values)
: this(value, _invariantCulture) : this(values, _invariantCulture)
{ {
} }
@ -49,88 +48,36 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
/// <param name="value">The submitted value.</param> /// <param name="value">The submitted value.</param>
/// <param name="culture">The <see cref="CultureInfo"/> associated with this value.</param> /// <param name="culture">The <see cref="CultureInfo"/> associated with this value.</param>
public ValueProviderResult(string value, CultureInfo culture) public ValueProviderResult(StringValues values, CultureInfo culture)
{ {
if (value == null) Values = values;
{
Value = null;
Values = None.Values;
}
else
{
Value = value;
Values = null;
}
Culture = culture ?? _invariantCulture; Culture = culture ?? _invariantCulture;
} }
/// <summary>
/// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>.
/// </summary>
/// <param name="values">The submitted values.</param>
public ValueProviderResult(string[] values)
: this(values, _invariantCulture)
{
}
/// <summary>
/// Creates a new <see cref="ValueProviderResult"/>.
/// </summary>
/// <param name="values">The submitted values.</param>
/// <param name="culture">The <see cref="CultureInfo"/> associated with these values.</param>
public ValueProviderResult(string[] values, CultureInfo culture)
{
if (values == null)
{
Value = null;
Values = None.Values;
}
else
{
Value = null;
Values = values;
}
Culture = culture;
}
/// <summary> /// <summary>
/// Gets or sets the <see cref="CultureInfo"/> associated with the values. /// Gets or sets the <see cref="CultureInfo"/> associated with the values.
/// </summary> /// </summary>
public CultureInfo Culture { get; private set; } public CultureInfo Culture { get; private set; }
/// <summary> /// <summary>
/// Gets or sets a single value. Will be <c>null</c> if multiple values are present. /// Gets or sets the values.
/// </summary> /// </summary>
public string Value { get; private set; } public StringValues Values { get; private set; }
/// <summary>
/// Gets or sets an array of values. Will be <c>null</c> if only a single value was provided.
/// </summary>
public string[] Values { get; private set; }
/// <summary> /// <summary>
/// Gets the first value based on the order values were provided in the request. Use <see cref="FirstValue"/> /// Gets the first value based on the order values were provided in the request. Use <see cref="FirstValue"/>
/// to get a single value for processing regarless of whether a single or multiple values were provided /// to get a single value for processing regardless of whether a single or multiple values were provided
/// in the request. /// in the request.
/// </summary> /// </summary>
public string FirstValue public string FirstValue
{ {
get get
{ {
if (Value != null) if (Values.Count == 0)
{
return Value;
}
else if (Values != null && Values.Length > 0)
{
return Values[0];
}
else
{ {
return null; return null;
} }
return Values[0];
} }
} }
@ -141,18 +88,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
get get
{ {
if (Values != null) return Values.Count;
{
return Values.Length;
}
else if (Value != null)
{
return 1;
}
else
{
return 0;
}
} }
} }
@ -172,9 +108,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
else else
{ {
var x = (string[])this; var x = Values;
var y = (string[])other; var y = other.Values;
for (var i = 0; i < x.Length; i++) for (var i = 0; i < x.Count; i++)
{ {
if (!string.Equals(x[i], y[i], StringComparison.Ordinal)) if (!string.Equals(x[i], y[i], StringComparison.Ordinal))
{ {
@ -188,28 +124,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <inheritdoc /> /// <inheritdoc />
public override int GetHashCode() public override int GetHashCode()
{ {
return ((string)this)?.GetHashCode() ?? 0; return ToString().GetHashCode();
} }
/// <inheritdoc /> /// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return (string)this; return Values.ToString();
} }
/// <summary> /// <summary>
/// Gets an <see cref="Enumerator"/> for this <see cref="ValueProviderResult"/>. /// Gets an <see cref="IEnumerator<string>"/> for this <see cref="ValueProviderResult"/>.
/// </summary> /// </summary>
/// <returns>An <see cref="Enumerator"/>.</returns> /// <returns>An <see cref="IEnumerator<string>"/>.</returns>
public Enumerator GetEnumerator() public IEnumerator<string> GetEnumerator()
{ {
return new Enumerator(this); return ((IEnumerable<string>)Values).GetEnumerator();
}
/// <inheritdoc />
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
return GetEnumerator();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -225,22 +155,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="result">The <see cref="ValueProviderResult"/>.</param> /// <param name="result">The <see cref="ValueProviderResult"/>.</param>
public static explicit operator string(ValueProviderResult result) public static explicit operator string(ValueProviderResult result)
{ {
if (result.Values == null) return result.Values;
{
return result.Value;
}
else if (result.Values.Length == 0)
{
return null;
}
else if (result.Values.Length == 1)
{
return result.Values[0];
}
else
{
return string.Join(",", result.Values);
}
} }
/// <summary> /// <summary>
@ -250,18 +165,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="result">The <see cref="ValueProviderResult"/>.</param> /// <param name="result">The <see cref="ValueProviderResult"/>.</param>
public static explicit operator string[](ValueProviderResult result) public static explicit operator string[](ValueProviderResult result)
{ {
if (result.Values != null) return result.Values;
{
return result.Values;
}
else if (result.Value != null)
{
return new string[] { result.Value };
}
else
{
return None.Values;
}
} }
/// <summary> /// <summary>
@ -285,71 +189,5 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
return !x.Equals(y); return !x.Equals(y);
} }
/// <summary>
/// An enumerator for <see cref="ValueProviderResult"/>.
/// </summary>
public struct Enumerator : IEnumerator<string>
{
private readonly ValueProviderResult _result;
private readonly int _length;
private int _index;
/// <summary>
/// Creates a new <see cref="Enumerator"/>.
/// </summary>
/// <param name="result">The <see cref="ValueProviderResult"/>.</param>
public Enumerator(ValueProviderResult result)
{
_result = result;
_index = -1;
_length = result.Length;
Current = null;
}
/// <inheritdoc />
public string Current { get; private set; }
/// <inheritdoc />
object IEnumerator.Current => Current;
/// <inheritdoc />
public void Dispose()
{
}
/// <inheritdoc />
public bool MoveNext()
{
++_index;
if (_index < _length)
{
if (_result.Values != null)
{
Debug.Assert(_index < _result.Values.Length);
Current = _result.Values[_index];
return true;
}
else if (_result.Value != null && _index == 0)
{
Current = _result.Value;
return true;
}
else
{
return false;
}
}
Current = null;
return false;
}
/// <inheritdoc />
public void Reset()
{
_index = -1;
}
}
} }
} }

View File

@ -7,6 +7,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Mvc
throw new InvalidOperationException(Resources.NoRoutesMatched); throw new InvalidOperationException(Resources.NoRoutesMatched);
} }
context.HttpContext.Response.Headers.Set("Location", url); context.HttpContext.Response.Headers[HeaderNames.Location] = url;
} }
} }
} }

View File

@ -7,6 +7,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -70,7 +71,7 @@ namespace Microsoft.AspNet.Mvc
throw new InvalidOperationException(Resources.NoRoutesMatched); throw new InvalidOperationException(Resources.NoRoutesMatched);
} }
context.HttpContext.Response.Headers.Set("Location", url); context.HttpContext.Response.Headers[HeaderNames.Location] = url;
} }
} }
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -50,7 +51,7 @@ namespace Microsoft.AspNet.Mvc
/// <inheritdoc /> /// <inheritdoc />
protected override void OnFormatting([NotNull] ActionContext context) protected override void OnFormatting([NotNull] ActionContext context)
{ {
context.HttpContext.Response.Headers.Set("Location", Location); context.HttpContext.Response.Headers[HeaderNames.Location] = Location;
} }
} }
} }

View File

@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Mvc
// basis for the actual filename, where possible. // basis for the actual filename, where possible.
var cd = new ContentDispositionHeaderValue("attachment"); var cd = new ContentDispositionHeaderValue("attachment");
cd.SetHttpFileName(FileDownloadName); cd.SetHttpFileName(FileDownloadName);
context.HttpContext.Response.Headers.Set(HeaderNames.ContentDisposition, cd.ToString()); context.HttpContext.Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();
} }
// We aren't flowing the cancellation token appropriately, see // We aren't flowing the cancellation token appropriately, see

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -62,12 +63,12 @@ namespace Microsoft.AspNet.Mvc
if (request.Headers.ContainsKey(OriginHeader)) if (request.Headers.ContainsKey(OriginHeader))
{ {
// Update the http method if it is preflight request. // Update the http method if it is preflight request.
var accessControlRequestMethod = request.Headers.Get(AccessControlRequestMethod); var accessControlRequestMethod = request.Headers[AccessControlRequestMethod];
if (string.Equals( if (string.Equals(
request.Method, request.Method,
PreflightHttpMethod, PreflightHttpMethod,
StringComparison.Ordinal) && StringComparison.Ordinal) &&
accessControlRequestMethod != null) !StringValues.IsNullOrEmpty(accessControlRequestMethod))
{ {
method = accessControlRequestMethod; method = accessControlRequestMethod;
} }

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -51,11 +52,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private class EmptyFormCollection : IFormCollection private class EmptyFormCollection : IFormCollection
{ {
public string this[string key] public StringValues this[string key]
{ {
get get
{ {
return null; return StringValues.Empty;
} }
} }
@ -93,12 +94,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return null; return null;
} }
public IEnumerator<KeyValuePair<string, string[]>> GetEnumerator() public IEnumerator<KeyValuePair<string, StringValues>> GetEnumerator()
{ {
return Enumerable.Empty<KeyValuePair<string, string[]>>().GetEnumerator(); return Enumerable.Empty<KeyValuePair<string, StringValues>>().GetEnumerator();
} }
public IList<string> GetValues(string key) public IList<StringValues> GetValues(string key)
{ {
return null; return null;
} }

View File

@ -2,11 +2,11 @@
// 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.Collections.Generic; using System.Collections.Generic;
using System.Linq;
#if DNXCORE50 #if DNXCORE50
using System.Reflection; using System.Reflection;
#endif #endif
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
object model = null; object model = null;
if (bindingContext.ModelType == typeof(string)) if (bindingContext.ModelType == typeof(string))
{ {
var value = request.Headers.Get(headerName); string value = request.Headers[headerName];
if (value != null) if (value != null)
{ {
model = value; model = value;
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
else if (typeof(IEnumerable<string>).IsAssignableFrom(bindingContext.ModelType)) else if (typeof(IEnumerable<string>).IsAssignableFrom(bindingContext.ModelType))
{ {
var values = request.Headers.GetCommaSeparatedValues(headerName); var values = request.Headers.GetCommaSeparatedValues(headerName);
if (values != null) if (values.Length > 0)
{ {
model = ModelBindingHelper.ConvertValuesToCollectionType( model = ModelBindingHelper.ConvertValuesToCollectionType(
bindingContext.ModelType, bindingContext.ModelType,
@ -60,11 +60,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
bindingContext.ModelName, bindingContext.ModelName,
bindingContext.ModelMetadata, bindingContext.ModelMetadata,
model); model);
bindingContext.ModelState.SetModelValue( bindingContext.ModelState.SetModelValue(
bindingContext.ModelName, bindingContext.ModelName,
request.Headers.GetCommaSeparatedValues(headerName).ToArray(), request.Headers.GetCommaSeparatedValues(headerName),
request.Headers.Get(headerName)); request.Headers[headerName]);
} }
return Task.FromResult( return Task.FromResult(

View File

@ -1,11 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -14,8 +15,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider
{ {
private readonly IDictionary<string, StringValues> _values;
private PrefixContainer _prefixContainer; private PrefixContainer _prefixContainer;
private readonly IDictionary<string, string[]> _values;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DictionaryBasedValueProvider"/> class. /// Initializes a new instance of the <see cref="DictionaryBasedValueProvider"/> class.
@ -25,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="culture">The culture to return with ValueProviderResult instances.</param> /// <param name="culture">The culture to return with ValueProviderResult instances.</param>
public JQueryFormValueProvider( public JQueryFormValueProvider(
[NotNull] BindingSource bindingSource, [NotNull] BindingSource bindingSource,
[NotNull] IDictionary<string, string[]> values, [NotNull] IDictionary<string, StringValues> values,
CultureInfo culture) CultureInfo culture)
: base(bindingSource) : base(bindingSource)
{ {
@ -64,8 +65,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <inheritdoc /> /// <inheritdoc />
public override ValueProviderResult GetValue(string key) public override ValueProviderResult GetValue(string key)
{ {
string[] values; StringValues values;
if (_values.TryGetValue(key, out values) && values != null && values.Length > 0) if (_values.TryGetValue(key, out values) && values.Count > 0)
{ {
return new ValueProviderResult(values, Culture); return new ValueProviderResult(values, Culture);
} }

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -29,11 +30,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return null; return null;
} }
private static async Task<IDictionary<string, string[]>> GetValueCollectionAsync(HttpRequest request) private static async Task<IDictionary<string, StringValues>> GetValueCollectionAsync(HttpRequest request)
{ {
var formCollection = await request.ReadFormAsync(); var formCollection = await request.ReadFormAsync();
var dictionary = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase); var dictionary = new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase);
foreach (var entry in formCollection) foreach (var entry in formCollection)
{ {
var key = NormalizeJQueryToMvc(entry.Key); var key = NormalizeJQueryToMvc(entry.Key);

View File

@ -1,12 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
@ -73,14 +69,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <inheritdoc /> /// <inheritdoc />
public override ValueProviderResult GetValue([NotNull] string key) public override ValueProviderResult GetValue([NotNull] string key)
{ {
var values = _values.GetValues(key); var values = _values[key];
if (values == null) if (values.Count == 0)
{ {
return ValueProviderResult.None; return ValueProviderResult.None;
} }
else else
{ {
return new ValueProviderResult(values.ToArray(), _culture); return new ValueProviderResult(values, _culture);
} }
} }
} }

View File

@ -21,7 +21,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </returns> /// </returns>
public static T ConvertTo<T>(this ValueProviderResult result) public static T ConvertTo<T>(this ValueProviderResult result)
{ {
var valueToConvert = (object)result.Values ?? (object)result.Value; object valueToConvert = null;
if (result.Values.Count == 1)
{
valueToConvert = result.Values[0];
}
else if (result.Values.Count > 1)
{
valueToConvert = result.Values.ToArray();
}
return ModelBindingHelper.ConvertTo<T>(valueToConvert, result.Culture); return ModelBindingHelper.ConvertTo<T>(valueToConvert, result.Culture);
} }
@ -35,7 +43,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </returns> /// </returns>
public static object ConvertTo(this ValueProviderResult result, [NotNull] Type type) public static object ConvertTo(this ValueProviderResult result, [NotNull] Type type)
{ {
var valueToConvert = (object)result.Values ?? (object)result.Value; object valueToConvert = null;
if (result.Values.Count == 1)
{
valueToConvert = result.Values[0];
}
else if (result.Values.Count > 1)
{
valueToConvert = result.Values.ToArray();
}
return ModelBindingHelper.ConvertTo(valueToConvert, type, result.Culture); return ModelBindingHelper.ConvertTo(valueToConvert, type, result.Culture);
} }
} }

View File

@ -4,8 +4,10 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -94,24 +96,24 @@ namespace Microsoft.AspNet.Mvc
var headers = context.HttpContext.Response.Headers; var headers = context.HttpContext.Response.Headers;
// Clear all headers // Clear all headers
headers.Remove("Vary"); headers.Remove(HeaderNames.Vary);
headers.Remove("Cache-control"); headers.Remove(HeaderNames.CacheControl);
headers.Remove("Pragma"); headers.Remove(HeaderNames.Pragma);
if (!string.IsNullOrEmpty(VaryByHeader)) if (!string.IsNullOrEmpty(VaryByHeader))
{ {
headers.Set("Vary", VaryByHeader); headers[HeaderNames.Vary] = VaryByHeader;
} }
if (NoStore) if (NoStore)
{ {
headers.Set("Cache-control", "no-store"); headers[HeaderNames.CacheControl] = "no-store";
// Cache-control: no-store, no-cache is valid. // Cache-control: no-store, no-cache is valid.
if (Location == ResponseCacheLocation.None) if (Location == ResponseCacheLocation.None)
{ {
headers.Append("Cache-control", "no-cache"); headers.AppendCommaSeparatedValues(HeaderNames.CacheControl, "no-cache");
headers.Set("Pragma", "no-cache"); headers[HeaderNames.Pragma] = "no-cache";
} }
} }
else else
@ -127,7 +129,7 @@ namespace Microsoft.AspNet.Mvc
break; break;
case ResponseCacheLocation.None: case ResponseCacheLocation.None:
cacheControlValue = "no-cache"; cacheControlValue = "no-cache";
headers.Set("Pragma", "no-cache"); headers[HeaderNames.Pragma] = "no-cache";
break; break;
} }
@ -140,7 +142,7 @@ namespace Microsoft.AspNet.Mvc
if (cacheControlValue != null) if (cacheControlValue != null)
{ {
headers.Set("Cache-control", cacheControlValue); headers[HeaderNames.CacheControl] = cacheControlValue;
} }
} }
} }

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc
private ICorsPolicyProvider _corsPolicyProvider; private ICorsPolicyProvider _corsPolicyProvider;
/// <summary> /// <summary>
/// Creates a new instace of <see cref="CorsAuthorizationFilter"/>. /// Creates a new instance of <see cref="CorsAuthorizationFilter"/>.
/// </summary> /// </summary>
/// <param name="corsService">The <see cref="ICorsService"/>.</param> /// <param name="corsService">The <see cref="ICorsService"/>.</param>
/// <param name="policyProvider">The <see cref="ICorsPolicyProvider"/>.</param> /// <param name="policyProvider">The <see cref="ICorsPolicyProvider"/>.</param>
@ -63,12 +64,12 @@ namespace Microsoft.AspNet.Mvc
_corsService.ApplyResult(result, context.HttpContext.Response); _corsService.ApplyResult(result, context.HttpContext.Response);
var accessControlRequestMethod = var accessControlRequestMethod =
httpContext.Request.Headers.Get(CorsConstants.AccessControlRequestMethod); httpContext.Request.Headers[CorsConstants.AccessControlRequestMethod];
if (string.Equals( if (string.Equals(
request.Method, request.Method,
CorsConstants.PreflightHttpMethod, CorsConstants.PreflightHttpMethod,
StringComparison.Ordinal) && StringComparison.Ordinal) &&
accessControlRequestMethod != null) !StringValues.IsNullOrEmpty(accessControlRequestMethod))
{ {
// If this was a preflight, there is no need to run anything else. // If this was a preflight, there is no need to run anything else.
// Also the response is always 200 so that anyone after mvc can handle the pre flight request. // Also the response is always 200 so that anyone after mvc can handle the pre flight request.

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -27,12 +28,12 @@ namespace Microsoft.AspNet.Mvc
public Task OnAuthorizationAsync([NotNull] AuthorizationContext context) public Task OnAuthorizationAsync([NotNull] AuthorizationContext context)
{ {
var accessControlRequestMethod = var accessControlRequestMethod =
context.HttpContext.Request.Headers.Get(CorsConstants.AccessControlRequestMethod); context.HttpContext.Request.Headers[CorsConstants.AccessControlRequestMethod];
if (string.Equals( if (string.Equals(
context.HttpContext.Request.Method, context.HttpContext.Request.Method,
CorsConstants.PreflightHttpMethod, CorsConstants.PreflightHttpMethod,
StringComparison.Ordinal) && StringComparison.Ordinal) &&
accessControlRequestMethod != null) !StringValues.IsNullOrEmpty(accessControlRequestMethod))
{ {
// Short circuit if the request is preflight as that should not result in action execution. // Short circuit if the request is preflight as that should not result in action execution.
context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK); context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK);

View File

@ -5,6 +5,7 @@ using System;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
foreach (var header in responseHeaders) foreach (var header in responseHeaders)
{ {
response.Headers.AppendValues(header.Key, header.Value.ToArray()); response.Headers.Append(header.Key, header.Value.ToArray());
} }
if (responseMessage.Content != null) if (responseMessage.Content != null)
@ -67,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
foreach (var header in contentHeaders) foreach (var header in contentHeaders)
{ {
response.Headers.AppendValues(header.Key, header.Value.ToArray()); response.Headers.Append(header.Key, header.Value.ToArray());
} }
await responseMessage.Content.CopyToAsync(response.Body); await responseMessage.Content.CopyToAsync(response.Body);

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Net.Http; using System.Net.Http;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
@ -58,9 +59,9 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
{ {
// Every header should be able to fit into one of the two header collections. // Every header should be able to fit into one of the two header collections.
// Try message.Headers first since that accepts more of them. // Try message.Headers first since that accepts more of them.
if (!message.Headers.TryAddWithoutValidation(header.Key, header.Value)) if (!message.Headers.TryAddWithoutValidation(header.Key, (IEnumerable<string>)header.Value))
{ {
var added = message.Content.Headers.TryAddWithoutValidation(header.Key, header.Value); var added = message.Content.Headers.TryAddWithoutValidation(header.Key, (IEnumerable<string>)header.Value);
Debug.Assert(added); Debug.Assert(added);
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
@ -15,12 +16,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Assert // Assert
Assert.Equal(0, result.Length); Assert.Equal(0, result.Length);
Assert.Null(result.Value);
Assert.Empty(result.Values); Assert.Empty(result.Values);
Assert.Null(result.FirstValue); Assert.Null(result.FirstValue);
Assert.Equal(ValueProviderResult.None, result); Assert.Equal(ValueProviderResult.None, result);
Assert.Null((string)result); Assert.Null((string)result);
Assert.Empty((string[])result); Assert.Null((string[])result);
} }
[Fact] [Fact]
@ -31,12 +31,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Assert // Assert
Assert.Equal(0, result.Length); Assert.Equal(0, result.Length);
Assert.Null(result.Value);
Assert.Empty(result.Values); Assert.Empty(result.Values);
Assert.Null(result.FirstValue); Assert.Null(result.FirstValue);
Assert.Equal(ValueProviderResult.None, result); Assert.Equal(ValueProviderResult.None, result);
Assert.Null((string)result); Assert.Null((string)result);
Assert.Empty((string[])result); Assert.Null((string[])result);
} }
[Fact] [Fact]
@ -47,10 +46,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Assert // Assert
Assert.Equal(0, result.Length); Assert.Equal(0, result.Length);
Assert.Null(result.Value);
Assert.Empty(result.Values); Assert.Empty(result.Values);
Assert.Null(result.FirstValue); Assert.Null(result.FirstValue);
Assert.Equal(ValueProviderResult.None, result); Assert.Equal(ValueProviderResult.None, result);
Assert.Equal(ValueProviderResult.None, new ValueProviderResult(new StringValues()));
Assert.Null((string)result); Assert.Null((string)result);
Assert.Empty((string[])result); Assert.Empty((string[])result);
} }
@ -63,8 +62,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Assert // Assert
Assert.Equal(1, result.Length); Assert.Equal(1, result.Length);
Assert.Equal("Hi There", result.Value); Assert.Equal("Hi There", result.Values);
Assert.Null(result.Values);
Assert.Equal("Hi There", result.FirstValue); Assert.Equal("Hi There", result.FirstValue);
Assert.NotEqual(ValueProviderResult.None, result); Assert.NotEqual(ValueProviderResult.None, result);
Assert.Equal("Hi There", (string)result); Assert.Equal("Hi There", (string)result);
@ -79,7 +77,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Assert // Assert
Assert.Equal(2, result.Length); Assert.Equal(2, result.Length);
Assert.Null(result.Value);
Assert.Equal(new string[] { "Hi", "There" }, result.Values); Assert.Equal(new string[] { "Hi", "There" }, result.Values);
Assert.Equal("Hi", result.FirstValue); Assert.Equal("Hi", result.FirstValue);
Assert.NotEqual(ValueProviderResult.None, result); Assert.NotEqual(ValueProviderResult.None, result);

View File

@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Mvc
var httpResponse = new Mock<HttpResponse>(); var httpResponse = new Mock<HttpResponse>();
httpResponse.SetupProperty(o => o.StatusCode); httpResponse.SetupProperty(o => o.StatusCode);
httpResponse.Setup(o => o.Headers).Returns( httpResponse.Setup(o => o.Headers).Returns(
new HeaderDictionary(new Dictionary<string, string[]>())); new HeaderDictionary());
httpResponse.SetupGet(o => o.Body).Returns(stream); httpResponse.SetupGet(o => o.Body).Returns(stream);
return httpResponse.Object; return httpResponse.Object;
} }

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Mvc
var location = "/test/"; var location = "/test/";
var httpContext = GetHttpContext(); var httpContext = GetHttpContext();
var actionContext = GetActionContext(httpContext); var actionContext = GetActionContext(httpContext);
httpContext.Response.Headers.Set("Location", "/different/location/"); httpContext.Response.Headers["Location"] = "/different/location/";
var result = new CreatedResult(location, "testInput"); var result = new CreatedResult(location, "testInput");
// Act // Act

View File

@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Mvc
// Query contains xml // Query contains xml
httpContext.Setup(c => c.Request.Query.ContainsKey("format")).Returns(true); httpContext.Setup(c => c.Request.Query.ContainsKey("format")).Returns(true);
httpContext.Setup(c => c.Request.Query.Get("format")).Returns("xml"); httpContext.Setup(c => c.Request.Query["format"]).Returns("xml");
// Routedata contains json // Routedata contains json
var data = new RouteData(); var data = new RouteData();

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
#if DNX451 #if DNX451
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Primitives;
using Moq; using Moq;
using Xunit; using Xunit;
#endif #endif
@ -18,11 +19,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
protected override IEnumerableValueProvider GetEnumerableValueProvider( protected override IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource, BindingSource bindingSource,
IDictionary<string, string[]> values, IDictionary<string, StringValues> values,
CultureInfo culture) CultureInfo culture)
{ {
var emptyValueProvider = var emptyValueProvider =
new JQueryFormValueProvider(bindingSource, new Dictionary<string, string[]>(), culture); new JQueryFormValueProvider(bindingSource, new Dictionary<string, StringValues>(), culture);
var valueProvider = new JQueryFormValueProvider(bindingSource, values, culture); var valueProvider = new JQueryFormValueProvider(bindingSource, values, culture);
return new CompositeValueProvider(new[] { emptyValueProvider, valueProvider }); return new CompositeValueProvider(new[] { emptyValueProvider, valueProvider });

View File

@ -8,6 +8,7 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.Framework.Primitives;
using Moq; using Moq;
using Xunit; using Xunit;
@ -453,10 +454,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
string keyFormat, string keyFormat,
IDictionary<string, string> dictionary) IDictionary<string, string> dictionary)
{ {
// Convert to an IDictionary<string, string[]> then wrap it up. // Convert to an IDictionary<string, StringValues> then wrap it up.
var backingStore = dictionary.ToDictionary( var backingStore = dictionary.ToDictionary(
kvp => string.Format(keyFormat, kvp.Key), kvp => string.Format(keyFormat, kvp.Key),
kvp => new[] { kvp.Value }); kvp => (StringValues)kvp.Value);
var stringCollection = new ReadableStringCollection(backingStore); var stringCollection = new ReadableStringCollection(backingStore);
return new ReadableStringCollectionValueProvider( return new ReadableStringCollectionValueProvider(

View File

@ -5,34 +5,35 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
public abstract class EnumerableValueProviderTest public abstract class EnumerableValueProviderTest
{ {
private static readonly IDictionary<string, string[]> _backingStore = new Dictionary<string, string[]> private static readonly IDictionary<string, StringValues> _backingStore = new Dictionary<string, StringValues>
{ {
{ "some", new[] { "someValue1", "someValue2" } }, { "some", new[] { "someValue1", "someValue2" } },
{ "null_value", null }, { "null_value", StringValues.Empty },
{ "prefix.name", new[] { "someOtherValue" } }, { "prefix.name", new[] { "someOtherValue" } },
{ "prefix.null_value", null }, { "prefix.null_value", StringValues.Empty },
{ "prefix.property1.property", null }, { "prefix.property1.property", StringValues.Empty },
{ "prefix.property2[index]", null }, { "prefix.property2[index]", StringValues.Empty },
{ "prefix[index1]", null }, { "prefix[index1]", StringValues.Empty },
{ "prefix[index1].property1", null }, { "prefix[index1].property1", StringValues.Empty },
{ "prefix[index1].property2", null }, { "prefix[index1].property2", StringValues.Empty },
{ "prefix[index2].property", null }, { "prefix[index2].property", StringValues.Empty },
{ "[index]", null }, { "[index]", StringValues.Empty },
{ "[index].property", null }, { "[index].property", StringValues.Empty },
{ "[index][anotherIndex]", null }, { "[index][anotherIndex]", StringValues.Empty },
}; };
[Fact] [Fact]
public void ContainsPrefix_WithEmptyCollection_ReturnsFalseForEmptyPrefix() public void ContainsPrefix_WithEmptyCollection_ReturnsFalseForEmptyPrefix()
{ {
// Arrange // Arrange
var backingStore = new Dictionary<string, string[]>(); var backingStore = new Dictionary<string, StringValues>();
var valueProvider = GetEnumerableValueProvider(BindingSource.Query, backingStore, culture: null); var valueProvider = GetEnumerableValueProvider(BindingSource.Query, backingStore, culture: null);
// Act // Act
@ -209,7 +210,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetValue_NullMultipleValue() public void GetValue_NullMultipleValue()
{ {
// Arrange // Arrange
var backingStore = new Dictionary<string, string[]> var backingStore = new Dictionary<string, StringValues>
{ {
{ "key", new string[] { null, null, "value" } }, { "key", new string[] { null, null, "value" } },
}; };
@ -278,7 +279,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private IBindingSourceValueProvider GetBindingSourceValueProvider( private IBindingSourceValueProvider GetBindingSourceValueProvider(
BindingSource bindingSource, BindingSource bindingSource,
IDictionary<string, string[]> values, IDictionary<string, StringValues> values,
CultureInfo culture) CultureInfo culture)
{ {
var provider = GetEnumerableValueProvider(bindingSource, values, culture) as IBindingSourceValueProvider; var provider = GetEnumerableValueProvider(bindingSource, values, culture) as IBindingSourceValueProvider;
@ -291,7 +292,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
protected abstract IEnumerableValueProvider GetEnumerableValueProvider( protected abstract IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource, BindingSource bindingSource,
IDictionary<string, string[]> values, IDictionary<string, StringValues> values,
CultureInfo culture); CultureInfo culture);
} }
} }

View File

@ -9,6 +9,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.Framework.Primitives;
using Moq; using Moq;
using Xunit; using Xunit;
@ -20,10 +21,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public async Task FormCollectionModelBinder_ValidType_BindSuccessful() public async Task FormCollectionModelBinder_ValidType_BindSuccessful()
{ {
// Arrange // Arrange
var formCollection = new FormCollection(new Dictionary<string, string[]> var formCollection = new FormCollection(new Dictionary<string, StringValues>
{ {
{ "field1", new string[] { "value1" } }, { "field1", "value1" },
{ "field2", new string[] { "value2" } } { "field2", "value2" }
}); });
var httpContext = GetMockHttpContext(formCollection); var httpContext = GetMockHttpContext(formCollection);
var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext); var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext);
@ -48,10 +49,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public async Task FormCollectionModelBinder_InvalidType_BindFails() public async Task FormCollectionModelBinder_InvalidType_BindFails()
{ {
// Arrange // Arrange
var formCollection = new FormCollection(new Dictionary<string, string[]> var formCollection = new FormCollection(new Dictionary<string, StringValues>
{ {
{ "field1", new string[] { "value1" } }, { "field1", "value1" },
{ "field2", new string[] { "value2" } } { "field2", "value2" }
}); });
var httpContext = GetMockHttpContext(formCollection); var httpContext = GetMockHttpContext(formCollection);
var bindingContext = GetBindingContext(typeof(string), httpContext); var bindingContext = GetBindingContext(typeof(string), httpContext);
@ -69,9 +70,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public async Task FormCollectionModelBinder_FormCollectionConcreteType_BindFails() public async Task FormCollectionModelBinder_FormCollectionConcreteType_BindFails()
{ {
// Arrange // Arrange
var formCollection = new FormCollection(new Dictionary<string, string[]> var formCollection = new FormCollection(new Dictionary<string, StringValues>
{ {
{ "field1", new string[] { "value1" } }, { "field1", "value1" },
{ "field2", new string[] { "value2" } } { "field2", new string[] { "value2" } }
}); });
var httpContext = GetMockHttpContext(formCollection); var httpContext = GetMockHttpContext(formCollection);
@ -131,11 +132,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private class MyFormCollection : ReadableStringCollection, IFormCollection private class MyFormCollection : ReadableStringCollection, IFormCollection
{ {
public MyFormCollection(IDictionary<string, string[]> store) : this(store, new FormFileCollection()) public MyFormCollection(IDictionary<string, StringValues> store) : this(store, new FormFileCollection())
{ {
} }
public MyFormCollection(IDictionary<string, string[]> store, IFormFileCollection files) : base(store) public MyFormCollection(IDictionary<string, StringValues> store, IFormFileCollection files) : base(store)
{ {
Files = files; Files = files;
} }

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding.Test namespace Microsoft.AspNet.Mvc.ModelBinding.Test
@ -52,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
if (context.Request.HasFormContentType) if (context.Request.HasFormContentType)
{ {
context.Request.Form = new FormCollection(new Dictionary<string, string[]>()); context.Request.Form = new FormCollection(new Dictionary<string, StringValues>());
} }
return new ValueProviderFactoryContext( return new ValueProviderFactoryContext(

View File

@ -6,13 +6,14 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding.Test namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{ {
public class JQueryFormValueProviderFactoryTest public class JQueryFormValueProviderFactoryTest
{ {
private static readonly IDictionary<string, string[]> _backingStore = new Dictionary<string, string[]> private static readonly IDictionary<string, StringValues> _backingStore = new Dictionary<string, StringValues>
{ {
{ "[]", new[] { "found" } }, { "[]", new[] { "found" } },
{ "[]property1", new[] { "found" } }, { "[]property1", new[] { "found" } },
@ -115,14 +116,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
private static ValueProviderFactoryContext CreateContext( private static ValueProviderFactoryContext CreateContext(
string contentType, string contentType,
IDictionary<string, string[]> formValues) IDictionary<string, StringValues> formValues)
{ {
var context = new DefaultHttpContext(); var context = new DefaultHttpContext();
context.Request.ContentType = contentType; context.Request.ContentType = contentType;
if (context.Request.HasFormContentType) if (context.Request.HasFormContentType)
{ {
context.Request.Form = new FormCollection(formValues ?? new Dictionary<string, string[]>()); context.Request.Form = new FormCollection(formValues ?? new Dictionary<string, StringValues>());
} }
return new ValueProviderFactoryContext( return new ValueProviderFactoryContext(

View File

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -10,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
protected override IEnumerableValueProvider GetEnumerableValueProvider( protected override IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource, BindingSource bindingSource,
IDictionary<string, string[]> values, IDictionary<string, StringValues> values,
CultureInfo culture) CultureInfo culture)
{ {
return new JQueryFormValueProvider(bindingSource, values, culture); return new JQueryFormValueProvider(bindingSource, values, culture);

View File

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -11,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
protected override IEnumerableValueProvider GetEnumerableValueProvider( protected override IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource, BindingSource bindingSource,
IDictionary<string, string[]> values, IDictionary<string, StringValues> values,
CultureInfo culture) CultureInfo culture)
{ {
var backingStore = new ReadableStringCollection(values); var backingStore = new ReadableStringCollection(values);

View File

@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal("no-store", context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal("no-store", context.HttpContext.Response.Headers["Cache-control"]);
} }
[Fact] [Fact]
@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal(output, context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
} }
public static IEnumerable<object[]> NoStoreData public static IEnumerable<object[]> NoStoreData
@ -205,7 +205,7 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal(output, context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
} }
public static IEnumerable<object[]> VaryData public static IEnumerable<object[]> VaryData
@ -275,8 +275,8 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal(varyOutput, context.HttpContext.Response.Headers.Get("Vary")); Assert.Equal(varyOutput, context.HttpContext.Response.Headers["Vary"]);
Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers["Cache-control"]);
} }
[Fact] [Fact]
@ -294,8 +294,8 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers["Cache-control"]);
Assert.Equal("no-cache", context.HttpContext.Response.Headers.Get("Pragma")); Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]);
} }
[Fact] [Fact]
@ -339,7 +339,7 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal("public,max-age=20", context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal("public,max-age=20", context.HttpContext.Response.Headers["Cache-control"]);
} }
[Fact] [Fact]
@ -359,7 +359,7 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal("private,max-age=10", context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal("private,max-age=10", context.HttpContext.Response.Headers["Cache-control"]);
} }
[Fact] [Fact]
@ -379,7 +379,7 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal("public,max-age=10", context.HttpContext.Response.Headers.Get("Cache-control")); Assert.Equal("public,max-age=10", context.HttpContext.Response.Headers["Cache-control"]);
} }
[Fact] [Fact]
@ -399,7 +399,7 @@ namespace Microsoft.AspNet.Mvc
cache.OnActionExecuting(context); cache.OnActionExecuting(context);
// Assert // Assert
Assert.Equal("Test", context.HttpContext.Response.Headers.Get("Vary")); Assert.Equal("Test", context.HttpContext.Response.Headers["Vary"]);
} }
private ActionExecutingContext GetActionExecutingContext(List<IFilterMetadata> filters = null) private ActionExecutingContext GetActionExecutingContext(List<IFilterMetadata> filters = null)

View File

@ -3,6 +3,7 @@
"warningsAsErrors": "true" "warningsAsErrors": "true"
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestCommon": { "Microsoft.AspNet.Mvc.TestCommon": {
"version": "6.0.0-*", "version": "6.0.0-*",

View File

@ -186,10 +186,9 @@ namespace Microsoft.AspNet.Mvc.Test
.Callback<CorsResult, HttpResponse>((result1, response1) => .Callback<CorsResult, HttpResponse>((result1, response1) =>
{ {
var headers = response1.Headers; var headers = response1.Headers;
headers.Set( headers[CorsConstants.AccessControlMaxAge] =
CorsConstants.AccessControlMaxAge, result1.PreflightMaxAge.Value.TotalSeconds.ToString();
result1.PreflightMaxAge.Value.TotalSeconds.ToString()); headers[CorsConstants.AccessControlAllowOrigin] = result1.AllowedOrigin;
headers.Add(CorsConstants.AccessControlAllowOrigin, new[] { result1.AllowedOrigin });
if (result1.SupportsCredentials) if (result1.SupportsCredentials)
{ {
headers.Add(CorsConstants.AccessControlAllowCredentials, new[] { "true" }); headers.Add(CorsConstants.AccessControlAllowCredentials, new[] { "true" });

View File

@ -3,6 +3,7 @@
"warningsAsErrors": "true" "warningsAsErrors": "true"
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml" : "6.0.0-*", "Microsoft.AspNet.Mvc.Formatters.Xml" : "6.0.0-*",
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" },

View File

@ -3,6 +3,7 @@
"warningsAsErrors": "true" "warningsAsErrors": "true"
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*", "Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" },

View File

@ -621,7 +621,7 @@ namespace Microsoft.AspNet.Mvc.Formatters.Xml
{ {
var request = new Mock<HttpRequest>(); var request = new Mock<HttpRequest>();
var headers = new HeaderDictionary(new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)); var headers = new HeaderDictionary();
headers["Accept-Charset"] = MediaTypeHeaderValue.Parse(contentType).Charset; headers["Accept-Charset"] = MediaTypeHeaderValue.Parse(contentType).Charset;
request.Setup(r => r.ContentType).Returns(contentType); request.Setup(r => r.ContentType).Returns(contentType);
request.SetupGet(r => r.Headers).Returns(headers); request.SetupGet(r => r.Headers).Returns(headers);

View File

@ -375,7 +375,7 @@ namespace Microsoft.AspNet.Mvc.Formatters.Xml
{ {
var request = new Mock<HttpRequest>(); var request = new Mock<HttpRequest>();
var headers = new HeaderDictionary(new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)); var headers = new HeaderDictionary();
headers["Accept-Charset"] = MediaTypeHeaderValue.Parse(contentType).Charset; headers["Accept-Charset"] = MediaTypeHeaderValue.Parse(contentType).Charset;
request.Setup(r => r.ContentType).Returns(contentType); request.Setup(r => r.ContentType).Returns(contentType);
request.SetupGet(r => r.Headers).Returns(headers); request.SetupGet(r => r.Headers).Returns(headers);

View File

@ -3,6 +3,7 @@
"warningsAsErrors": "true" "warningsAsErrors": "true"
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Mvc" : "6.0.0-*", "Microsoft.AspNet.Mvc" : "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml" : "6.0.0-*", "Microsoft.AspNet.Mvc.Formatters.Xml" : "6.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",

View File

@ -68,12 +68,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
var body = await response.Content.ReadAsStringAsync(); var body = await response.Content.ReadAsStringAsync();
var filters = response.Headers.GetValues("filters").Single().Split(','); var filters = response.Headers.GetValues("filters").ToArray();
var i = 0; var i = 0;
foreach (var filter in filters) foreach (var filter in filters)
{ {
Assert.Equal(filter, expected[i++]); Assert.Equal(expected[i++], filter);
} }
Assert.Equal(expected.Length, filters.Length); Assert.Equal(expected.Length, filters.Length);

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.IntegrationTests namespace Microsoft.AspNet.Mvc.IntegrationTests
@ -604,7 +605,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request =>
{ {
var formCollection = new FormCollection(new Dictionary<string, string[]>() var formCollection = new FormCollection(new Dictionary<string, StringValues>()
{ {
{ "Addresses.index", new [] { "Key1", "Key2" } }, { "Addresses.index", new [] { "Key1", "Key2" } },
{ "Addresses[Key1].Street", new [] { "Street1" } }, { "Addresses[Key1].Street", new [] { "Street1" } },
@ -663,7 +664,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request =>
{ {
var formCollection = new FormCollection(new Dictionary<string, string[]>() var formCollection = new FormCollection(new Dictionary<string, StringValues>()
{ {
{ "Addresses.index", new [] { "Key1" } }, { "Addresses.index", new [] { "Key1" } },
{ "Addresses[Key1].Street", new [] { "Street1" } }, { "Addresses[Key1].Street", new [] { "Street1" } },
@ -733,15 +734,15 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
} }
// parameter type, form content, expected type // parameter type, form content, expected type
public static TheoryData<Type, IDictionary<string, string[]>, Type> CollectionTypeData public static TheoryData<Type, IDictionary<string, StringValues>, Type> CollectionTypeData
{ {
get get
{ {
return new TheoryData<Type, IDictionary<string, string[]>, Type> return new TheoryData<Type, IDictionary<string, StringValues>, Type>
{ {
{ {
typeof(IEnumerable<string>), typeof(IEnumerable<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[0]", new[] { "hello" } }, { "[0]", new[] { "hello" } },
{ "[1]", new[] { "world" } }, { "[1]", new[] { "world" } },
@ -750,7 +751,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ICollection<string>), typeof(ICollection<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "index", new[] { "low", "high" } }, { "index", new[] { "low", "high" } },
{ "[low]", new[] { "hello" } }, { "[low]", new[] { "hello" } },
@ -760,7 +761,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(IList<string>), typeof(IList<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[0]", new[] { "hello" } }, { "[0]", new[] { "hello" } },
{ "[1]", new[] { "world" } }, { "[1]", new[] { "world" } },
@ -769,7 +770,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(List<string>), typeof(List<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "index", new[] { "low", "high" } }, { "index", new[] { "low", "high" } },
{ "[low]", new[] { "hello" } }, { "[low]", new[] { "hello" } },
@ -779,7 +780,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ClosedGenericCollection), typeof(ClosedGenericCollection),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[0]", new[] { "hello" } }, { "[0]", new[] { "hello" } },
{ "[1]", new[] { "world" } }, { "[1]", new[] { "world" } },
@ -788,7 +789,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ClosedGenericList), typeof(ClosedGenericList),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "index", new[] { "low", "high" } }, { "index", new[] { "low", "high" } },
{ "[low]", new[] { "hello" } }, { "[low]", new[] { "hello" } },
@ -798,7 +799,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitClosedGenericCollection), typeof(ExplicitClosedGenericCollection),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[0]", new[] { "hello" } }, { "[0]", new[] { "hello" } },
{ "[1]", new[] { "world" } }, { "[1]", new[] { "world" } },
@ -807,7 +808,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitClosedGenericList), typeof(ExplicitClosedGenericList),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "index", new[] { "low", "high" } }, { "index", new[] { "low", "high" } },
{ "[low]", new[] { "hello" } }, { "[low]", new[] { "hello" } },
@ -817,7 +818,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitCollection<string>), typeof(ExplicitCollection<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[0]", new[] { "hello" } }, { "[0]", new[] { "hello" } },
{ "[1]", new[] { "world" } }, { "[1]", new[] { "world" } },
@ -826,7 +827,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitList<string>), typeof(ExplicitList<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "index", new[] { "low", "high" } }, { "index", new[] { "low", "high" } },
{ "[low]", new[] { "hello" } }, { "[low]", new[] { "hello" } },
@ -836,7 +837,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(IEnumerable<string>), typeof(IEnumerable<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ string.Empty, new[] { "hello", "world" } }, { string.Empty, new[] { "hello", "world" } },
}, },
@ -844,7 +845,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ICollection<string>), typeof(ICollection<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[]", new[] { "hello", "world" } }, { "[]", new[] { "hello", "world" } },
}, },
@ -852,7 +853,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(IList<string>), typeof(IList<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ string.Empty, new[] { "hello", "world" } }, { string.Empty, new[] { "hello", "world" } },
}, },
@ -860,7 +861,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(List<string>), typeof(List<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[]", new[] { "hello", "world" } }, { "[]", new[] { "hello", "world" } },
}, },
@ -868,7 +869,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ClosedGenericCollection), typeof(ClosedGenericCollection),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ string.Empty, new[] { "hello", "world" } }, { string.Empty, new[] { "hello", "world" } },
}, },
@ -876,7 +877,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ClosedGenericList), typeof(ClosedGenericList),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[]", new[] { "hello", "world" } }, { "[]", new[] { "hello", "world" } },
}, },
@ -884,7 +885,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitClosedGenericCollection), typeof(ExplicitClosedGenericCollection),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ string.Empty, new[] { "hello", "world" } }, { string.Empty, new[] { "hello", "world" } },
}, },
@ -892,7 +893,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitClosedGenericList), typeof(ExplicitClosedGenericList),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[]", new[] { "hello", "world" } }, { "[]", new[] { "hello", "world" } },
}, },
@ -900,7 +901,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitCollection<string>), typeof(ExplicitCollection<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ string.Empty, new[] { "hello", "world" } }, { string.Empty, new[] { "hello", "world" } },
}, },
@ -908,7 +909,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}, },
{ {
typeof(ExplicitList<string>), typeof(ExplicitList<string>),
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "[]", new[] { "hello", "world" } }, { "[]", new[] { "hello", "world" } },
}, },
@ -922,7 +923,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
[MemberData(nameof(CollectionTypeData))] [MemberData(nameof(CollectionTypeData))]
public async Task CollectionModelBinder_BindsParameterToExpectedType( public async Task CollectionModelBinder_BindsParameterToExpectedType(
Type parameterType, Type parameterType,
IDictionary<string, string[]> formContent, IDictionary<string, StringValues> formContent,
Type expectedType) Type expectedType)
{ {
// Arrange // Arrange

View File

@ -9,6 +9,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Http.Features.Internal;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.IntegrationTests namespace Microsoft.AspNet.Mvc.IntegrationTests
@ -163,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
private void UpdateRequest(HttpRequest request, string data, string name) private void UpdateRequest(HttpRequest request, string data, string name)
{ {
var fileCollection = new FormFileCollection(); var fileCollection = new FormFileCollection();
var formCollection = new FormCollection(new Dictionary<string, string[]>(), fileCollection); var formCollection = new FormCollection(new Dictionary<string, StringValues>(), fileCollection);
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(data)); var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(data));
request.Form = formCollection; request.Form = formCollection;

View File

@ -9,6 +9,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Http.Features.Internal;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.IntegrationTests namespace Microsoft.AspNet.Mvc.IntegrationTests
@ -164,7 +165,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
private void UpdateRequest(HttpRequest request, string data, string name) private void UpdateRequest(HttpRequest request, string data, string name)
{ {
var fileCollection = new FormFileCollection(); var fileCollection = new FormFileCollection();
var formCollection = new FormCollection(new Dictionary<string, string[]>(), fileCollection); var formCollection = new FormCollection(new Dictionary<string, StringValues>(), fileCollection);
request.Form = formCollection; request.Form = formCollection;
request.ContentType = "multipart/form-data; boundary=----WebKitFormBoundarymx2fSWqWSd0OxQqq"; request.ContentType = "multipart/form-data; boundary=----WebKitFormBoundarymx2fSWqWSd0OxQqq";

View File

@ -10,6 +10,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Http.Features.Internal;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.IntegrationTests namespace Microsoft.AspNet.Mvc.IntegrationTests
@ -2129,7 +2130,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
private static void SetFormFileBodyContent(HttpRequest request, string content, string name) private static void SetFormFileBodyContent(HttpRequest request, string content, string name)
{ {
var fileCollection = new FormFileCollection(); var fileCollection = new FormFileCollection();
var formCollection = new FormCollection(new Dictionary<string, string[]>(), fileCollection); var formCollection = new FormCollection(new Dictionary<string, StringValues>(), fileCollection);
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(content)); var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(content));
request.Form = formCollection; request.Form = formCollection;

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Primitives;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.IntegrationTests namespace Microsoft.AspNet.Mvc.IntegrationTests
@ -366,19 +367,19 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
Assert.Empty(modelState.Keys); Assert.Empty(modelState.Keys);
} }
public static TheoryData<IDictionary<string, string[]>> PersonStoreData public static TheoryData<IDictionary<string, StringValues>> PersonStoreData
{ {
get get
{ {
return new TheoryData<IDictionary<string, string[]>> return new TheoryData<IDictionary<string, StringValues>>
{ {
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "name", new[] { "Fred" } }, { "name", new[] { "Fred" } },
{ "address.zip", new[] { "98052" } }, { "address.zip", new[] { "98052" } },
{ "address.lines", new[] { "line 1", "line 2" } }, { "address.lines", new[] { "line 1", "line 2" } },
}, },
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "address.lines[]", new[] { "line 1", "line 2" } }, { "address.lines[]", new[] { "line 1", "line 2" } },
{ "address[].zip", new[] { "98052" } }, { "address[].zip", new[] { "98052" } },
@ -390,7 +391,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
[Theory] [Theory]
[MemberData(nameof(PersonStoreData))] [MemberData(nameof(PersonStoreData))]
public async Task BindParameter_FromFormData_BindsCorrectly(IDictionary<string, string[]> personStore) public async Task BindParameter_FromFormData_BindsCorrectly(IDictionary<string, StringValues> personStore)
{ {
// Arrange // Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();

View File

@ -3,6 +3,7 @@
"warningsAsErrors": "true" "warningsAsErrors": "true"
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*", "Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestCommon": { "Microsoft.AspNet.Mvc.TestCommon": {

View File

@ -3,6 +3,7 @@
"warningsAsErrors": "true" "warningsAsErrors": "true"
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*", "Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" },

View File

@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShimTest
// Assert // Assert
Assert.True(httpContext.Response.Headers.ContainsKey(transferEncodingHeaderKey)); Assert.True(httpContext.Response.Headers.ContainsKey(transferEncodingHeaderKey));
Assert.Equal(new string[] { "identity", "chunked" }, Assert.Equal(new string[] { "identity", "chunked" },
httpContext.Response.Headers.GetValues(transferEncodingHeaderKey)); httpContext.Response.Headers[transferEncodingHeaderKey]);
Assert.NotNull(httpContext.Response.ContentLength); Assert.NotNull(httpContext.Response.ContentLength);
} }
@ -141,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShimTest
// Assert // Assert
Assert.True(httpContext.Response.Headers.ContainsKey(transferEncodingHeaderKey)); Assert.True(httpContext.Response.Headers.ContainsKey(transferEncodingHeaderKey));
Assert.Equal(new string[] { "identity", "chunked" }, Assert.Equal(new string[] { "identity", "chunked" },
httpContext.Response.Headers.GetValues(transferEncodingHeaderKey)); httpContext.Response.Headers[transferEncodingHeaderKey]);
Assert.NotNull(httpContext.Response.ContentLength); Assert.NotNull(httpContext.Response.ContentLength);
} }

View File

@ -63,7 +63,7 @@ namespace CustomRouteWebSite
private string GetLocale(HttpContext context) private string GetLocale(HttpContext context)
{ {
string locale; string locale;
_users.TryGetValue(context.Request.Headers.Get("User"), out locale); _users.TryGetValue(context.Request.Headers["User"], out locale);
return locale; return locale;
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -2,6 +2,7 @@
// 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.Security.Claims; using System.Security.Claims;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -2,6 +2,7 @@
// 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.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -2,6 +2,7 @@
// 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.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -2,6 +2,7 @@
// 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; using System;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
namespace FiltersWebSite namespace FiltersWebSite

View File

@ -1,6 +1,5 @@
using System; using System.Collections.Generic;
using System.Collections.Generic; using Microsoft.Framework.Primitives;
using Microsoft.AspNet.Http;
namespace LoggingWebSite namespace LoggingWebSite
{ {
@ -22,10 +21,10 @@ namespace LoggingWebSite
public string Protocol { get; set; } public string Protocol { get; set; }
public IEnumerable<KeyValuePair<string, string[]>> Headers { get; set; } public IEnumerable<KeyValuePair<string, StringValues>> Headers { get; set; }
public string Query { get; set; } public string Query { get; set; }
public IEnumerable<KeyValuePair<string, string[]>> Cookies { get; set; } public IEnumerable<KeyValuePair<string, StringValues>> Cookies { get; set; }
} }
} }

View File

@ -73,7 +73,7 @@ namespace ModelBindingWebSite.Controllers
// Doing something slightly different here to make sure we don't get accidentally bound // Doing something slightly different here to make sure we don't get accidentally bound
// by the type converter binder. // by the type converter binder.
OrderStatus model; OrderStatus model;
var isModelSet = Enum.TryParse<OrderStatus>("Status" + request.Query.Get("status"), out model); var isModelSet = Enum.TryParse<OrderStatus>("Status" + request.Query["status"], out model);
var validationNode = var validationNode =
new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, model); new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, model);
return Task.FromResult(new ModelBindingResult(model, "status", isModelSet, validationNode)); return Task.FromResult(new ModelBindingResult(model, "status", isModelSet, validationNode));

View File

@ -10,6 +10,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Primitives;
using ModelBindingWebSite.Models; using ModelBindingWebSite.Models;
namespace ModelBindingWebSite.Controllers namespace ModelBindingWebSite.Controllers
@ -107,7 +108,7 @@ namespace ModelBindingWebSite.Controllers
public async Task<Employee> GetEmployeeAsync_BindToBaseDeclaredType() public async Task<Employee> GetEmployeeAsync_BindToBaseDeclaredType()
{ {
var backingStore = new ReadableStringCollection( var backingStore = new ReadableStringCollection(
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "Parent.Name", new[] { "fatherName"} }, { "Parent.Name", new[] { "fatherName"} },
{ "Parent.Parent.Name", new[] {"grandFatherName" } }, { "Parent.Parent.Name", new[] {"grandFatherName" } },
@ -131,7 +132,7 @@ namespace ModelBindingWebSite.Controllers
public async Task<User> GetUserAsync_ModelType_IncludeAll(int id) public async Task<User> GetUserAsync_ModelType_IncludeAll(int id)
{ {
var backingStore = new ReadableStringCollection( var backingStore = new ReadableStringCollection(
new Dictionary<string, string[]> new Dictionary<string, StringValues>
{ {
{ "Key", new[] { "123"} }, { "Key", new[] { "123"} },
{ "RegisterationMonth", new[] {"March" } }, { "RegisterationMonth", new[] {"March" } },

View File

@ -46,7 +46,7 @@ namespace ResponseCacheWebSite
[ResponseCache(Duration = 40)] [ResponseCache(Duration = 40)]
public IActionResult SetHeadersInAction() public IActionResult SetHeadersInAction()
{ {
Response.Headers.Set("Cache-control", "max-age=10"); Response.Headers["Cache-control"] = "max-age=10";
return Content("Hello World!"); return Content("Hello World!");
} }

View File

@ -21,7 +21,7 @@ namespace VersioningWebSite
public static string GetVersion(HttpRequest request) public static string GetVersion(HttpRequest request)
{ {
return request.Query.Get("version"); return request.Query["version"];
} }
public bool Accept(ActionConstraintContext context) public bool Accept(ActionConstraintContext context)