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

Commit 25af3ee

Browse files
committed
React to string[] -> StringValues changes.
1 parent dfd3dd0 commit 25af3ee

File tree

9 files changed

+55
-42
lines changed

9 files changed

+55
-42
lines changed

src/Microsoft.AspNet.Authentication.Cookies/ChunkingCookieManager.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.Linq;
88
using Microsoft.AspNet.Http;
9+
using Microsoft.AspNet.Primitives;
910
using Microsoft.Framework.Internal;
1011
using Microsoft.Framework.WebEncoders;
1112
using Microsoft.Net.Http.Headers;
@@ -151,7 +152,7 @@ public void AppendResponseCookie([NotNull] HttpContext context, [NotNull] string
151152
if (!ChunkSize.HasValue || ChunkSize.Value > templateLength + escapedValue.Length + (quoted ? 2 : 0))
152153
{
153154
template.Value = quoted ? Quote(escapedValue) : escapedValue;
154-
responseHeaders.AppendValues(Constants.Headers.SetCookie, template.ToString());
155+
responseHeaders.Append(Constants.Headers.SetCookie, template.ToString());
155156
}
156157
else if (ChunkSize.Value < templateLength + (quoted ? 2 : 0) + 10)
157158
{
@@ -171,7 +172,7 @@ public void AppendResponseCookie([NotNull] HttpContext context, [NotNull] string
171172
var cookieChunkCount = (int)Math.Ceiling(escapedValue.Length * 1.0 / dataSizePerCookie);
172173

173174
template.Value = "chunks:" + cookieChunkCount.ToString(CultureInfo.InvariantCulture);
174-
responseHeaders.AppendValues(Constants.Headers.SetCookie, template.ToString());
175+
responseHeaders.Append(Constants.Headers.SetCookie, template.ToString());
175176

176177
var chunks = new string[cookieChunkCount];
177178
var offset = 0;
@@ -186,7 +187,7 @@ public void AppendResponseCookie([NotNull] HttpContext context, [NotNull] string
186187
template.Value = quoted ? Quote(segment) : segment;
187188
chunks[chunkId - 1] = template.ToString();
188189
}
189-
responseHeaders.AppendValues(Constants.Headers.SetCookie, chunks);
190+
responseHeaders.Append(Constants.Headers.SetCookie, chunks);
190191
}
191192
}
192193

@@ -233,10 +234,10 @@ public void DeleteCookie([NotNull] HttpContext context, [NotNull] string key, [N
233234
}
234235

235236
var responseHeaders = context.Response.Headers;
236-
var existingValues = responseHeaders.GetValues(Constants.Headers.SetCookie);
237-
if (existingValues != null)
237+
var existingValues = responseHeaders[Constants.Headers.SetCookie];
238+
if (!StringValues.IsNullOrEmpty(existingValues))
238239
{
239-
responseHeaders.SetValues(Constants.Headers.SetCookie, existingValues.Where(value => !rejectPredicate(value)).ToArray());
240+
responseHeaders[Constants.Headers.SetCookie] = existingValues.Where(value => !rejectPredicate(value)).ToArray();
240241
}
241242

242243
AppendResponseCookie(

src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.AspNet.Http;
1010
using Microsoft.AspNet.Http.Authentication;
1111
using Microsoft.AspNet.Http.Features.Authentication;
12+
using Microsoft.AspNet.Primitives;
1213
using Microsoft.Framework.Internal;
1314
using Microsoft.Framework.Logging;
1415

@@ -344,15 +345,15 @@ protected override async Task HandleSignOutAsync(SignOutContext signOutContext)
344345

345346
private void ApplyHeaders(bool shouldRedirectToReturnUrl = false)
346347
{
347-
Response.Headers.Set(HeaderNameCacheControl, HeaderValueNoCache);
348-
Response.Headers.Set(HeaderNamePragma, HeaderValueNoCache);
349-
Response.Headers.Set(HeaderNameExpires, HeaderValueMinusOne);
348+
Response.Headers[HeaderNameCacheControl] = HeaderValueNoCache;
349+
Response.Headers[HeaderNamePragma] = HeaderValueNoCache;
350+
Response.Headers[HeaderNameExpires] = HeaderValueMinusOne;
350351

351352
if (shouldRedirectToReturnUrl && Response.StatusCode == 200)
352353
{
353354
var query = Request.Query;
354-
var redirectUri = query.Get(Options.ReturnUrlParameter);
355-
if (!string.IsNullOrEmpty(redirectUri)
355+
var redirectUri = query[Options.ReturnUrlParameter];
356+
if (!StringValues.IsNullOrEmpty(redirectUri)
356357
&& IsHostRelative(redirectUri))
357358
{
358359
var redirectContext = new CookieApplyRedirectContext(Context, Options, redirectUri);

src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync(string code,
4242
var payload = new JObject();
4343
foreach (string key in form.Keys)
4444
{
45-
payload.Add(string.Equals(key, "expires", StringComparison.OrdinalIgnoreCase) ? "expires_in" : key, form[key]);
45+
payload.Add(string.Equals(key, "expires", StringComparison.OrdinalIgnoreCase) ? "expires_in" : key, (string)form[key]);
4646
}
4747

4848
// The refresh token is not available.

src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
using System.Collections.Generic;
66
using System.Net.Http;
77
using System.Net.Http.Headers;
8-
using System.Security.Cryptography;
98
using System.Security.Claims;
9+
using System.Security.Cryptography;
1010
using System.Threading.Tasks;
1111
using Microsoft.AspNet.Http;
1212
using Microsoft.AspNet.Http.Authentication;
1313
using Microsoft.AspNet.Http.Extensions;
1414
using Microsoft.AspNet.Http.Features.Authentication;
15+
using Microsoft.AspNet.Primitives;
1516
using Microsoft.AspNet.WebUtilities;
1617
using Microsoft.Framework.Internal;
1718
using Microsoft.Framework.Logging;
@@ -85,16 +86,16 @@ protected override async Task<AuthenticationTicket> HandleAuthenticateAsync()
8586
var query = Request.Query;
8687

8788
// TODO: Is this a standard error returned by servers?
88-
var value = query.Get("error");
89-
if (!string.IsNullOrEmpty(value))
89+
var value = query["error"];
90+
if (!StringValues.IsNullOrEmpty(value))
9091
{
9192
Logger.LogVerbose("Remote server returned an error: " + Request.QueryString);
9293
// TODO: Fail request rather than passing through?
9394
return null;
9495
}
9596

96-
var code = query.Get("code");
97-
var state = query.Get("state");
97+
var code = query["code"];
98+
var state = query["state"];
9899

99100
properties = Options.StateDataFormat.Unprotect(state);
100101
if (properties == null)
@@ -108,7 +109,7 @@ protected override async Task<AuthenticationTicket> HandleAuthenticateAsync()
108109
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
109110
}
110111

111-
if (string.IsNullOrEmpty(code))
112+
if (StringValues.IsNullOrEmpty(code))
112113
{
113114
// Null if the remote server returns an error.
114115
return new AuthenticationTicket(properties, Options.AuthenticationScheme);

src/Microsoft.AspNet.Authentication.OAuthBearer/Notifications/OAuthBearerAuthenticationNotifications.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class OAuthBearerAuthenticationNotifications
2020
/// </summary>
2121
public OAuthBearerAuthenticationNotifications()
2222
{
23-
ApplyChallenge = notification => { notification.HttpContext.Response.Headers.AppendValues("WWW-Authenticate", notification.Options.Challenge); return Task.FromResult(0); };
23+
ApplyChallenge = notification => { notification.HttpContext.Response.Headers.Append("WWW-Authenticate", notification.Options.Challenge); return Task.FromResult(0); };
2424
AuthenticationFailed = notification => Task.FromResult(0);
2525
MessageReceived = notification => Task.FromResult(0);
2626
SecurityTokenReceived = notification => Task.FromResult(0);

src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected override async Task<AuthenticationTicket> HandleAuthenticateAsync()
5050

5151
if (string.IsNullOrEmpty(token))
5252
{
53-
var authorization = Request.Headers.Get("Authorization");
53+
string authorization = Request.Headers["Authorization"];
5454

5555
// If no authorization header found, nothing to process further
5656
if (string.IsNullOrEmpty(authorization))

src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Globalization;
67
using System.IdentityModel.Tokens;
78
using System.IdentityModel.Tokens.Jwt;
@@ -246,7 +247,7 @@ protected override async Task<AuthenticationTicket> HandleAuthenticateAsync()
246247

247248
if (string.Equals(Request.Method, "GET", StringComparison.OrdinalIgnoreCase))
248249
{
249-
message = new OpenIdConnectMessage(Request.Query);
250+
message = new OpenIdConnectMessage(Request.Query.Select(pair => new KeyValuePair<string, string[]>(pair.Key, pair.Value)));
250251

251252
// response_mode=query (explicit or not) and a response_type containing id_token
252253
// or token are not considered as a safe combination and MUST be rejected.
@@ -267,7 +268,7 @@ protected override async Task<AuthenticationTicket> HandleAuthenticateAsync()
267268
{
268269
var form = await Request.ReadFormAsync();
269270
Request.Body.Seek(0, SeekOrigin.Begin);
270-
message = new OpenIdConnectMessage(form);
271+
message = new OpenIdConnectMessage(form.Select(pair => new KeyValuePair<string, string[]>(pair.Key, pair.Value)));
271272
}
272273

273274
if (message == null)

src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.AspNet.Http.Authentication;
1414
using Microsoft.AspNet.Http.Features.Authentication;
1515
using Microsoft.AspNet.Http.Internal;
16+
using Microsoft.AspNet.Primitives;
1617
using Microsoft.AspNet.WebUtilities;
1718
using Microsoft.Framework.Internal;
1819
using Microsoft.Framework.Logging;
@@ -61,21 +62,21 @@ protected override async Task<AuthenticationTicket> HandleAuthenticateAsync()
6162

6263
properties = requestToken.Properties;
6364

64-
var returnedToken = query.Get("oauth_token");
65-
if (string.IsNullOrEmpty(returnedToken))
65+
var returnedToken = query["oauth_token"];
66+
if (StringValues.IsNullOrEmpty(returnedToken))
6667
{
6768
Logger.LogWarning("Missing oauth_token");
6869
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
6970
}
7071

71-
if (returnedToken != requestToken.Token)
72+
if (!string.Equals(returnedToken, requestToken.Token, StringComparison.Ordinal))
7273
{
7374
Logger.LogWarning("Unmatched token");
7475
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
7576
}
7677

77-
var oauthVerifier = query.Get("oauth_verifier");
78-
if (string.IsNullOrEmpty(oauthVerifier))
78+
var oauthVerifier = query["oauth_verifier"];
79+
if (StringValues.IsNullOrEmpty(oauthVerifier))
7980
{
8081
Logger.LogWarning("Missing or blank oauth_verifier");
8182
return new AuthenticationTicket(properties, Options.AuthenticationScheme);

test/Microsoft.AspNet.Authentication.Test/Cookies/Infrastructure/CookieChunkingTests.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void AppendLargeCookie_Appended()
1818

1919
string testString = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2020
new ChunkingCookieManager(null) { ChunkSize = null }.AppendResponseCookie(context, "TestCookie", testString, new CookieOptions());
21-
IList<string> values = context.Response.Headers.GetValues("Set-Cookie");
21+
var values = context.Response.Headers["Set-Cookie"];
2222
Assert.Equal(1, values.Count);
2323
Assert.Equal("TestCookie=" + testString + "; path=/", values[0]);
2424
}
@@ -30,9 +30,9 @@ public void AppendLargeCookieWithLimit_Chunked()
3030

3131
string testString = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
3232
new ChunkingCookieManager(null) { ChunkSize = 30 }.AppendResponseCookie(context, "TestCookie", testString, new CookieOptions());
33-
IList<string> values = context.Response.Headers.GetValues("Set-Cookie");
33+
var values = context.Response.Headers["Set-Cookie"];
3434
Assert.Equal(9, values.Count);
35-
Assert.Equal(new[]
35+
Assert.Equal<string[]>(new[]
3636
{
3737
"TestCookie=chunks:8; path=/",
3838
"TestCookieC1=abcdefgh; path=/",
@@ -53,9 +53,9 @@ public void AppendLargeQuotedCookieWithLimit_QuotedChunked()
5353

5454
string testString = "\"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\"";
5555
new ChunkingCookieManager(null) { ChunkSize = 32 }.AppendResponseCookie(context, "TestCookie", testString, new CookieOptions());
56-
IList<string> values = context.Response.Headers.GetValues("Set-Cookie");
56+
var values = context.Response.Headers["Set-Cookie"];
5757
Assert.Equal(9, values.Count);
58-
Assert.Equal(new[]
58+
Assert.Equal<string[]>(new[]
5959
{
6060
"TestCookie=chunks:8; path=/",
6161
"TestCookieC1=\"abcdefgh\"; path=/",
@@ -73,15 +73,17 @@ public void AppendLargeQuotedCookieWithLimit_QuotedChunked()
7373
public void GetLargeChunkedCookie_Reassembled()
7474
{
7575
HttpContext context = new DefaultHttpContext();
76-
context.Request.Headers.AppendValues("Cookie",
76+
context.Request.Headers["Cookie"] = new[]
77+
{
7778
"TestCookie=chunks:7",
7879
"TestCookieC1=abcdefghi",
7980
"TestCookieC2=jklmnopqr",
8081
"TestCookieC3=stuvwxyz0",
8182
"TestCookieC4=123456789",
8283
"TestCookieC5=ABCDEFGHI",
8384
"TestCookieC6=JKLMNOPQR",
84-
"TestCookieC7=STUVWXYZ");
85+
"TestCookieC7=STUVWXYZ"
86+
};
8587

8688
string result = new ChunkingCookieManager(null).GetRequestCookie(context, "TestCookie");
8789
string testString = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -92,15 +94,17 @@ public void GetLargeChunkedCookie_Reassembled()
9294
public void GetLargeChunkedCookieWithQuotes_Reassembled()
9395
{
9496
HttpContext context = new DefaultHttpContext();
95-
context.Request.Headers.AppendValues("Cookie",
97+
context.Request.Headers["Cookie"] = new[]
98+
{
9699
"TestCookie=chunks:7",
97100
"TestCookieC1=\"abcdefghi\"",
98101
"TestCookieC2=\"jklmnopqr\"",
99102
"TestCookieC3=\"stuvwxyz0\"",
100103
"TestCookieC4=\"123456789\"",
101104
"TestCookieC5=\"ABCDEFGHI\"",
102105
"TestCookieC6=\"JKLMNOPQR\"",
103-
"TestCookieC7=\"STUVWXYZ\"");
106+
"TestCookieC7=\"STUVWXYZ\""
107+
};
104108

105109
string result = new ChunkingCookieManager(null).GetRequestCookie(context, "TestCookie");
106110
string testString = "\"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\"";
@@ -111,15 +115,17 @@ public void GetLargeChunkedCookieWithQuotes_Reassembled()
111115
public void GetLargeChunkedCookieWithMissingChunk_ThrowingEnabled_Throws()
112116
{
113117
HttpContext context = new DefaultHttpContext();
114-
context.Request.Headers.AppendValues("Cookie",
118+
context.Request.Headers["Cookie"] = new[]
119+
{
115120
"TestCookie=chunks:7",
116121
"TestCookieC1=abcdefghi",
117122
// Missing chunk "TestCookieC2=jklmnopqr",
118123
"TestCookieC3=stuvwxyz0",
119124
"TestCookieC4=123456789",
120125
"TestCookieC5=ABCDEFGHI",
121126
"TestCookieC6=JKLMNOPQR",
122-
"TestCookieC7=STUVWXYZ");
127+
"TestCookieC7=STUVWXYZ"
128+
};
123129

124130
Assert.Throws<FormatException>(() => new ChunkingCookieManager(null).GetRequestCookie(context, "TestCookie"));
125131
}
@@ -128,15 +134,17 @@ public void GetLargeChunkedCookieWithMissingChunk_ThrowingEnabled_Throws()
128134
public void GetLargeChunkedCookieWithMissingChunk_ThrowingDisabled_NotReassembled()
129135
{
130136
HttpContext context = new DefaultHttpContext();
131-
context.Request.Headers.AppendValues("Cookie",
137+
context.Request.Headers["Cookie"] = new[]
138+
{
132139
"TestCookie=chunks:7",
133140
"TestCookieC1=abcdefghi",
134141
// Missing chunk "TestCookieC2=jklmnopqr",
135142
"TestCookieC3=stuvwxyz0",
136143
"TestCookieC4=123456789",
137144
"TestCookieC5=ABCDEFGHI",
138145
"TestCookieC6=JKLMNOPQR",
139-
"TestCookieC7=STUVWXYZ");
146+
"TestCookieC7=STUVWXYZ"
147+
};
140148

141149
string result = new ChunkingCookieManager(null) { ThrowForPartialCookies = false }.GetRequestCookie(context, "TestCookie");
142150
string testString = "chunks:7";
@@ -147,10 +155,10 @@ public void GetLargeChunkedCookieWithMissingChunk_ThrowingDisabled_NotReassemble
147155
public void DeleteChunkedCookieWithOptions_AllDeleted()
148156
{
149157
HttpContext context = new DefaultHttpContext();
150-
context.Request.Headers.AppendValues("Cookie", "TestCookie=chunks:7");
158+
context.Request.Headers.Append("Cookie", "TestCookie=chunks:7");
151159

152160
new ChunkingCookieManager(null).DeleteCookie(context, "TestCookie", new CookieOptions() { Domain = "foo.com" });
153-
var cookies = context.Response.Headers.GetValues("Set-Cookie");
161+
var cookies = context.Response.Headers["Set-Cookie"];
154162
Assert.Equal(8, cookies.Count);
155163
Assert.Equal(new[]
156164
{

0 commit comments

Comments
 (0)