Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 6331a9c

Browse files
committed
React to string[] -> StringValues changes.
1 parent e61ebca commit 6331a9c

File tree

42 files changed

+154
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+154
-126
lines changed

src/Microsoft.AspNet.Mvc.Core/CreatedAtActionResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNet.Mvc.Core;
88
using Microsoft.Framework.DependencyInjection;
99
using Microsoft.Framework.Internal;
10+
using Microsoft.Net.Http.Headers;
1011

1112
namespace Microsoft.AspNet.Mvc
1213
{
@@ -73,7 +74,7 @@ protected override void OnFormatting([NotNull] ActionContext context)
7374
throw new InvalidOperationException(Resources.NoRoutesMatched);
7475
}
7576

76-
context.HttpContext.Response.Headers.Set("Location", url);
77+
context.HttpContext.Response.Headers[HeaderNames.Location] = url;
7778
}
7879
}
7980
}

src/Microsoft.AspNet.Mvc.Core/CreatedAtRouteResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNet.Mvc.Core;
88
using Microsoft.Framework.DependencyInjection;
99
using Microsoft.Framework.Internal;
10+
using Microsoft.Net.Http.Headers;
1011

1112
namespace Microsoft.AspNet.Mvc
1213
{
@@ -70,7 +71,7 @@ protected override void OnFormatting([NotNull] ActionContext context)
7071
throw new InvalidOperationException(Resources.NoRoutesMatched);
7172
}
7273

73-
context.HttpContext.Response.Headers.Set("Location", url);
74+
context.HttpContext.Response.Headers[HeaderNames.Location] = url;
7475
}
7576
}
7677
}

src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using Microsoft.AspNet.Http;
66
using Microsoft.Framework.Internal;
7+
using Microsoft.Net.Http.Headers;
78

89
namespace Microsoft.AspNet.Mvc
910
{
@@ -50,7 +51,7 @@ public string Location
5051
/// <inheritdoc />
5152
protected override void OnFormatting([NotNull] ActionContext context)
5253
{
53-
context.HttpContext.Response.Headers.Set("Location", Location);
54+
context.HttpContext.Response.Headers[HeaderNames.Location] = Location;
5455
}
5556
}
5657
}

src/Microsoft.AspNet.Mvc.Core/FileResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public override Task ExecuteResultAsync([NotNull] ActionContext context)
6868
// basis for the actual filename, where possible.
6969
var cd = new ContentDispositionHeaderValue("attachment");
7070
cd.SetHttpFileName(FileDownloadName);
71-
context.HttpContext.Response.Headers.Set(HeaderNames.ContentDisposition, cd.ToString());
71+
context.HttpContext.Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();
7272
}
7373

7474
// We aren't flowing the cancellation token appropriately, see

src/Microsoft.AspNet.Mvc.Core/HttpMethodConstraint.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Collections.ObjectModel;
77
using System.Linq;
8+
using Microsoft.AspNet.Primitives;
89
using Microsoft.Framework.Internal;
910

1011
namespace Microsoft.AspNet.Mvc
@@ -62,12 +63,12 @@ public bool Accept([NotNull] ActionConstraintContext context)
6263
if (request.Headers.ContainsKey(OriginHeader))
6364
{
6465
// Update the http method if it is preflight request.
65-
var accessControlRequestMethod = request.Headers.Get(AccessControlRequestMethod);
66+
var accessControlRequestMethod = request.Headers[AccessControlRequestMethod];
6667
if (string.Equals(
6768
request.Method,
6869
PreflightHttpMethod,
6970
StringComparison.Ordinal) &&
70-
accessControlRequestMethod != null)
71+
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
7172
{
7273
method = accessControlRequestMethod;
7374
}

src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.AspNet.Http;
99
using Microsoft.AspNet.Http.Internal;
10+
using Microsoft.AspNet.Primitives;
1011
using Microsoft.Framework.Internal;
1112

1213
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -42,7 +43,7 @@ public async Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingConte
4243
}
4344
else
4445
{
45-
model = new FormCollection(new Dictionary<string, string[]>());
46+
model = new FormCollection(new Dictionary<string, StringValues>());
4647
}
4748

4849
var validationNode =

src/Microsoft.AspNet.Mvc.Core/ModelBinding/HeaderModelBinder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reflection;
88
#endif
99
using System.Threading.Tasks;
10+
using Microsoft.AspNet.Primitives;
1011
using Microsoft.Framework.Internal;
1112

1213
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -36,7 +37,7 @@ protected override Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBi
3637
object model = null;
3738
if (bindingContext.ModelType == typeof(string))
3839
{
39-
var value = request.Headers.Get(headerName);
40+
string value = request.Headers[headerName];
4041
if (value != null)
4142
{
4243
model = value;
@@ -45,7 +46,7 @@ protected override Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBi
4546
else if (typeof(IEnumerable<string>).IsAssignableFrom(bindingContext.ModelType))
4647
{
4748
var values = request.Headers.GetCommaSeparatedValues(headerName);
48-
if (values != null)
49+
if (values.Count > 0)
4950
{
5051
model = ModelBindingHelper.ConvertValuesToCollectionType(
5152
bindingContext.ModelType,
@@ -61,7 +62,7 @@ protected override Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBi
6162
bindingContext.ModelMetadata,
6263
model);
6364

64-
var attemptedValue = (model as string) ?? request.Headers.Get(headerName);
65+
var attemptedValue = (model as string) ?? request.Headers[headerName];
6566
var valueProviderResult = new ValueProviderResult(model, attemptedValue, CultureInfo.InvariantCulture);
6667
bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult);
6768
}

src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProvider.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.Globalization;
88
using System.Threading.Tasks;
9+
using Microsoft.AspNet.Primitives;
910
using Microsoft.Framework.Internal;
1011

1112
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -16,10 +17,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
1617
/// </summary>
1718
public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider
1819
{
19-
private readonly Func<Task<IDictionary<string, string[]>>> _valuesFactory;
20+
private readonly Func<Task<IDictionary<string, StringValues>>> _valuesFactory;
2021

2122
private PrefixContainer _prefixContainer;
22-
private IDictionary<string, string[]> _values;
23+
private IDictionary<string, StringValues> _values;
2324

2425
/// <summary>
2526
/// Initializes a new instance of the <see cref="DictionaryBasedValueProvider"/> class.
@@ -29,7 +30,7 @@ public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableVa
2930
/// <param name="culture">The culture to return with ValueProviderResult instances.</param>
3031
public JQueryFormValueProvider(
3132
[NotNull] BindingSource bindingSource,
32-
[NotNull] Func<Task<IDictionary<string, string[]>>> valuesFactory,
33+
[NotNull] Func<Task<IDictionary<string, StringValues>>> valuesFactory,
3334
CultureInfo culture)
3435
: base(bindingSource)
3536
{
@@ -40,7 +41,7 @@ public JQueryFormValueProvider(
4041
// Internal for testing.
4142
internal JQueryFormValueProvider(
4243
[NotNull] BindingSource bindingSource,
43-
[NotNull] IDictionary<string, string[]> values,
44+
[NotNull] IDictionary<string, StringValues> values,
4445
CultureInfo culture)
4546
: base(bindingSource)
4647
{
@@ -70,22 +71,26 @@ public override async Task<ValueProviderResult> GetValueAsync(string key)
7071
{
7172
var dictionary = await GetDictionary();
7273

73-
string[] values;
74-
if (dictionary.TryGetValue(key, out values) && values != null && values.Length > 0)
74+
StringValues values;
75+
if (dictionary.TryGetValue(key, out values) && values.Count > 0)
7576
{
76-
// Success.
77-
if (values.Length == 1)
77+
if (values.Count == 1)
7878
{
79-
return new ValueProviderResult(values[0], values[0], Culture);
79+
var value = (string)values;
80+
return new ValueProviderResult(value, value, Culture);
81+
}
82+
else
83+
{
84+
var rawValue = (string[])values;
85+
var value = (string)values;
86+
return new ValueProviderResult(rawValue, value, Culture);
8087
}
81-
82-
return new ValueProviderResult(values, string.Join(",", values), Culture);
8388
}
8489

8590
return null;
8691
}
8792

88-
private async Task<IDictionary<string, string[]>> GetDictionary()
93+
private async Task<IDictionary<string, StringValues>> GetDictionary()
8994
{
9095
if (_values == null)
9196
{

src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99
using Microsoft.AspNet.Http;
1010
using Microsoft.AspNet.Mvc.Core;
11+
using Microsoft.AspNet.Primitives;
1112
using Microsoft.Framework.Internal;
1213

1314
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -29,11 +30,11 @@ public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext con
2930
return null;
3031
}
3132

32-
private static async Task<IDictionary<string, string[]>> GetValueCollectionAsync(HttpRequest request)
33+
private static async Task<IDictionary<string, StringValues>> GetValueCollectionAsync(HttpRequest request)
3334
{
3435
var formCollection = await request.ReadFormAsync();
3536

36-
var dictionary = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
37+
var dictionary = new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase);
3738
foreach (var entry in formCollection)
3839
{
3940
var key = NormalizeJQueryToMvc(entry.Key);

src/Microsoft.AspNet.Mvc.Core/ModelBinding/ReadableStringCollectionValueProvider.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Globalization;
88
using System.Threading.Tasks;
99
using Microsoft.AspNet.Http;
10+
using Microsoft.AspNet.Primitives;
1011
using Microsoft.Framework.Internal;
1112

1213
namespace Microsoft.AspNet.Mvc.ModelBinding
@@ -80,21 +81,21 @@ public virtual async Task<IDictionary<string, string>> GetKeysFromPrefixAsync([N
8081
public override async Task<ValueProviderResult> GetValueAsync([NotNull] string key)
8182
{
8283
var collection = await GetValueCollectionAsync();
83-
var values = collection.GetValues(key);
84+
var values = collection[key];
8485

8586
ValueProviderResult result;
86-
if (values == null)
87+
if (values.Count == 0)
8788
{
8889
result = null;
8990
}
9091
else if (values.Count == 1)
9192
{
92-
var value = (string)values[0];
93+
var value = (string)values;
9394
result = new ValueProviderResult(value, value, _culture);
9495
}
9596
else
9697
{
97-
result = new ValueProviderResult(values, _values.Get(key), _culture);
98+
result = new ValueProviderResult((string[])values, _values[key], _culture);
9899
}
99100

100101
return result;

src/Microsoft.AspNet.Mvc.Core/ResponseCacheFilter.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using Microsoft.AspNet.Mvc.Core;
88
using Microsoft.Framework.Internal;
9+
using Microsoft.Net.Http.Headers;
910

1011
namespace Microsoft.AspNet.Mvc
1112
{
@@ -94,24 +95,24 @@ public void OnActionExecuting([NotNull] ActionExecutingContext context)
9495
var headers = context.HttpContext.Response.Headers;
9596

9697
// Clear all headers
97-
headers.Remove("Vary");
98-
headers.Remove("Cache-control");
99-
headers.Remove("Pragma");
98+
headers.Remove(HeaderNames.Vary);
99+
headers.Remove(HeaderNames.CacheControl);
100+
headers.Remove(HeaderNames.Pragma);
100101

101102
if (!string.IsNullOrEmpty(VaryByHeader))
102103
{
103-
headers.Set("Vary", VaryByHeader);
104+
headers[HeaderNames.Vary] = VaryByHeader;
104105
}
105106

106107
if (NoStore)
107108
{
108-
headers.Set("Cache-control", "no-store");
109+
headers[HeaderNames.CacheControl] = "no-store";
109110

110111
// Cache-control: no-store, no-cache is valid.
111112
if (Location == ResponseCacheLocation.None)
112113
{
113-
headers.Append("Cache-control", "no-cache");
114-
headers.Set("Pragma", "no-cache");
114+
headers.AppendCommaSeparatedValues(HeaderNames.CacheControl, "no-cache");
115+
headers[HeaderNames.Pragma] = "no-cache";
115116
}
116117
}
117118
else
@@ -127,7 +128,7 @@ public void OnActionExecuting([NotNull] ActionExecutingContext context)
127128
break;
128129
case ResponseCacheLocation.None:
129130
cacheControlValue = "no-cache";
130-
headers.Set("Pragma", "no-cache");
131+
headers[HeaderNames.Pragma] = "no-cache";
131132
break;
132133
}
133134

@@ -140,7 +141,7 @@ public void OnActionExecuting([NotNull] ActionExecutingContext context)
140141

141142
if (cacheControlValue != null)
142143
{
143-
headers.Set("Cache-control", cacheControlValue);
144+
headers[HeaderNames.CacheControl] = cacheControlValue;
144145
}
145146
}
146147
}

src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.AspNet.Cors.Core;
99
using Microsoft.AspNet.Http;
10+
using Microsoft.AspNet.Primitives;
1011
using Microsoft.Framework.Internal;
1112

1213
namespace Microsoft.AspNet.Mvc
@@ -63,12 +64,12 @@ public async Task OnAuthorizationAsync([NotNull] AuthorizationContext context)
6364
_corsService.ApplyResult(result, context.HttpContext.Response);
6465

6566
var accessControlRequestMethod =
66-
httpContext.Request.Headers.Get(CorsConstants.AccessControlRequestMethod);
67+
httpContext.Request.Headers[CorsConstants.AccessControlRequestMethod];
6768
if (string.Equals(
6869
request.Method,
6970
CorsConstants.PreflightHttpMethod,
7071
StringComparison.Ordinal) &&
71-
accessControlRequestMethod != null)
72+
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
7273
{
7374
// If this was a preflight, there is no need to run anything else.
7475
// Also the response is always 200 so that anyone after mvc can handle the pre flight request.

src/Microsoft.AspNet.Mvc.Cors/DisableCorsAuthorizationFilter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNet.Cors.Core;
77
using Microsoft.AspNet.Http;
8+
using Microsoft.AspNet.Primitives;
89
using Microsoft.Framework.Internal;
910

1011
namespace Microsoft.AspNet.Mvc
@@ -27,12 +28,12 @@ public int Order
2728
public Task OnAuthorizationAsync([NotNull] AuthorizationContext context)
2829
{
2930
var accessControlRequestMethod =
30-
context.HttpContext.Request.Headers.Get(CorsConstants.AccessControlRequestMethod);
31+
context.HttpContext.Request.Headers[CorsConstants.AccessControlRequestMethod];
3132
if (string.Equals(
3233
context.HttpContext.Request.Method,
3334
CorsConstants.PreflightHttpMethod,
3435
StringComparison.Ordinal) &&
35-
accessControlRequestMethod != null)
36+
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
3637
{
3738
// Short circuit if the request is preflight as that should not result in action execution.
3839
context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK);

src/Microsoft.AspNet.Mvc.WebApiCompatShim/Formatters/HttpResponseMessageOutputFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public async Task WriteAsync(OutputFormatterContext context)
5353

5454
foreach (var header in responseHeaders)
5555
{
56-
response.Headers.AppendValues(header.Key, header.Value.ToArray());
56+
response.Headers.Append(header.Key, header.Value.ToArray());
5757
}
5858

5959
if (responseMessage.Content != null)
@@ -67,7 +67,7 @@ public async Task WriteAsync(OutputFormatterContext context)
6767

6868
foreach (var header in contentHeaders)
6969
{
70-
response.Headers.AppendValues(header.Key, header.Value.ToArray());
70+
response.Headers.Append(header.Key, header.Value.ToArray());
7171
}
7272

7373
await responseMessage.Content.CopyToAsync(response.Body);

0 commit comments

Comments
 (0)