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

Commit 09d6ab0

Browse files
committed
Re-use public constants for header names.
1 parent c8f24b2 commit 09d6ab0

File tree

8 files changed

+27
-46
lines changed

8 files changed

+27
-46
lines changed

src/Microsoft.AspNet.Http.Core/Collections/ResponseCookies.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using System.Collections.Generic;
66
using System.Globalization;
77
using System.Linq;
8-
using Microsoft.AspNet.Http.Infrastructure;
98
using Microsoft.Framework.Internal;
109
using Microsoft.Framework.WebEncoders;
10+
using Microsoft.Net.Http.Headers;
1111

1212
namespace Microsoft.AspNet.Http.Core.Collections
1313
{
@@ -34,7 +34,7 @@ public ResponseCookies([NotNull] IHeaderDictionary headers)
3434
/// <param name="value"></param>
3535
public void Append(string key, string value)
3636
{
37-
Headers.AppendValues(Constants.Headers.SetCookie, UrlEncoder.Default.UrlEncode(key) + "=" + UrlEncoder.Default.UrlEncode(value) + "; path=/");
37+
Headers.AppendValues(HeaderNames.SetCookie, UrlEncoder.Default.UrlEncode(key) + "=" + UrlEncoder.Default.UrlEncode(value) + "; path=/");
3838
}
3939

4040
/// <summary>
@@ -61,7 +61,7 @@ public void Append(string key, string value, [NotNull] CookieOptions options)
6161
!expiresHasValue ? null : options.Expires.Value.ToString("ddd, dd-MMM-yyyy HH:mm:ss ", CultureInfo.InvariantCulture) + "GMT",
6262
!options.Secure ? null : "; secure",
6363
!options.HttpOnly ? null : "; HttpOnly");
64-
Headers.AppendValues("Set-Cookie", setCookieValue);
64+
Headers.AppendValues(HeaderNames.SetCookie, setCookieValue);
6565
}
6666

6767
/// <summary>
@@ -73,14 +73,14 @@ public void Delete(string key)
7373
Func<string, bool> predicate = value => value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase);
7474

7575
var deleteCookies = new[] { UrlEncoder.Default.UrlEncode(key) + "=; expires=Thu, 01-Jan-1970 00:00:00 GMT" };
76-
IList<string> existingValues = Headers.GetValues(Constants.Headers.SetCookie);
76+
IList<string> existingValues = Headers.GetValues(HeaderNames.SetCookie);
7777
if (existingValues == null || existingValues.Count == 0)
7878
{
79-
Headers.SetValues(Constants.Headers.SetCookie, deleteCookies);
79+
Headers.SetValues(HeaderNames.SetCookie, deleteCookies);
8080
}
8181
else
8282
{
83-
Headers.SetValues(Constants.Headers.SetCookie, existingValues.Where(value => !predicate(value)).Concat(deleteCookies).ToArray());
83+
Headers.SetValues(HeaderNames.SetCookie, existingValues.Where(value => !predicate(value)).Concat(deleteCookies).ToArray());
8484
}
8585
}
8686

@@ -112,10 +112,10 @@ public void Delete(string key, [NotNull] CookieOptions options)
112112
rejectPredicate = value => value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase);
113113
}
114114

115-
IList<string> existingValues = Headers.GetValues(Constants.Headers.SetCookie);
115+
IList<string> existingValues = Headers.GetValues(HeaderNames.SetCookie);
116116
if (existingValues != null)
117117
{
118-
Headers.SetValues(Constants.Headers.SetCookie, existingValues.Where(value => !rejectPredicate(value)).ToArray());
118+
Headers.SetValues(HeaderNames.SetCookie, existingValues.Where(value => !rejectPredicate(value)).ToArray());
119119
}
120120

121121
Append(key, string.Empty, new CookieOptions

src/Microsoft.AspNet.Http.Core/DefaultHttpContext.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
76
using System.Net.WebSockets;
87
using System.Security.Claims;
98
using System.Threading;
@@ -13,8 +12,8 @@
1312
using Microsoft.AspNet.Http.Core.Authentication;
1413
using Microsoft.AspNet.Http.Core.Collections;
1514
using Microsoft.AspNet.Http.Core.Infrastructure;
16-
using Microsoft.AspNet.Http.Infrastructure;
1715
using Microsoft.Framework.Internal;
16+
using Microsoft.Net.Http.Headers;
1817

1918
namespace Microsoft.AspNet.Http.Core
2019
{
@@ -169,7 +168,7 @@ public override IList<string> WebSocketRequestedProtocols
169168
{
170169
get
171170
{
172-
return Request.Headers.GetValues(Constants.Headers.WebSocketSubProtocols) ?? EmptyList;
171+
return Request.Headers.GetValues(HeaderNames.WebSocketSubProtocols) ?? EmptyList;
173172
}
174173
}
175174

src/Microsoft.AspNet.Http.Core/DefaultHttpRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Microsoft.AspNet.FeatureModel;
9-
using Microsoft.AspNet.Http;
10-
using Microsoft.AspNet.Http.Infrastructure;
119
using Microsoft.AspNet.Http.Core.Collections;
1210
using Microsoft.AspNet.Http.Core.Infrastructure;
11+
using Microsoft.AspNet.Http.Infrastructure;
12+
using Microsoft.Net.Http.Headers;
1313

1414
namespace Microsoft.AspNet.Http.Core
1515
{
@@ -113,7 +113,7 @@ public override string Scheme
113113

114114
public override bool IsHttps
115115
{
116-
get { return string.Equals("https", Scheme, StringComparison.OrdinalIgnoreCase); }
116+
get { return string.Equals(Constants.Https, Scheme, StringComparison.OrdinalIgnoreCase); }
117117
}
118118

119119
public override HostString Host
@@ -145,8 +145,8 @@ public override IReadableStringCollection Cookies
145145

146146
public override string ContentType
147147
{
148-
get { return Headers[Constants.Headers.ContentType]; }
149-
set { Headers[Constants.Headers.ContentType] = value; }
148+
get { return Headers[HeaderNames.ContentType]; }
149+
set { Headers[HeaderNames.ContentType] = value; }
150150
}
151151

152152
public override bool HasFormContentType

src/Microsoft.AspNet.Http.Core/DefaultHttpResponse.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
using Microsoft.AspNet.Http.Core.Authentication;
1212
using Microsoft.AspNet.Http.Core.Collections;
1313
using Microsoft.AspNet.Http.Core.Infrastructure;
14-
using Microsoft.AspNet.Http.Infrastructure;
1514
using Microsoft.Framework.Internal;
15+
using Microsoft.Net.Http.Headers;
1616

1717
namespace Microsoft.AspNet.Http.Core
1818
{
@@ -80,18 +80,18 @@ public override string ContentType
8080
{
8181
get
8282
{
83-
var contentType = Headers[Constants.Headers.ContentType];
83+
var contentType = Headers[HeaderNames.ContentType];
8484
return contentType;
8585
}
8686
set
8787
{
8888
if (string.IsNullOrWhiteSpace(value))
8989
{
90-
HttpResponseFeature.Headers.Remove(Constants.Headers.ContentType);
90+
HttpResponseFeature.Headers.Remove(HeaderNames.ContentType);
9191
}
9292
else
9393
{
94-
HttpResponseFeature.Headers[Constants.Headers.ContentType] = new[] { value };
94+
HttpResponseFeature.Headers[HeaderNames.ContentType] = new[] { value };
9595
}
9696
}
9797
}
@@ -127,7 +127,7 @@ public override void Redirect(string location, bool permanent)
127127
HttpResponseFeature.StatusCode = 302;
128128
}
129129

130-
Headers.Set(Constants.Headers.Location, location);
130+
Headers.Set(HeaderNames.Location, location);
131131
}
132132

133133
public override void Challenge(AuthenticationProperties properties, [NotNull] IEnumerable<string> authenticationSchemes)

src/Microsoft.AspNet.Http.Core/Infrastructure/Constants.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,6 @@ internal static class Constants
77
{
88
internal const string Https = "HTTPS";
99

10-
internal const string HttpDateFormat = "r";
11-
12-
internal static class Headers
13-
{
14-
internal const string ContentType = "Content-Type";
15-
internal const string CacheControl = "Cache-Control";
16-
internal const string MediaType = "Media-Type";
17-
internal const string Accept = "Accept";
18-
internal const string AcceptCharset = "Accept-Charset";
19-
internal const string Host = "Host";
20-
internal const string ETag = "ETag";
21-
internal const string Location = "Location";
22-
internal const string ContentLength = "Content-Length";
23-
internal const string Cookie = "Cookie";
24-
internal const string SetCookie = "Set-Cookie";
25-
internal const string Expires = "Expires";
26-
internal const string WebSocketSubProtocols = "Sec-WebSocket-Protocol";
27-
}
28-
2910
internal static class BuilderProperties
3011
{
3112
internal static string ServerInformation = "server.Information";

src/Microsoft.AspNet.Http.Core/Infrastructure/ParsingHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using System.Collections.Generic;
77
using System.Globalization;
88
using System.Linq;
9-
using Microsoft.AspNet.Http.Infrastructure;
109
using Microsoft.Framework.Internal;
10+
using Microsoft.Net.Http.Headers;
1111

1212
namespace Microsoft.AspNet.Http.Core.Infrastructure
1313
{
@@ -775,7 +775,7 @@ internal static string[] GetUnmodifiedValues([NotNull] IDictionary<string, strin
775775
{
776776
const NumberStyles styles = NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite;
777777
long value;
778-
string rawValue = headers.Get(Constants.Headers.ContentLength);
778+
string rawValue = headers.Get(HeaderNames.ContentLength);
779779
if (!string.IsNullOrWhiteSpace(rawValue) &&
780780
long.TryParse(rawValue, styles, CultureInfo.InvariantCulture, out value))
781781
{
@@ -789,11 +789,11 @@ public static void SetContentLength([NotNull] IHeaderDictionary headers, long? v
789789
{
790790
if (value.HasValue)
791791
{
792-
headers[Constants.Headers.ContentLength] = value.Value.ToString(CultureInfo.InvariantCulture);
792+
headers[HeaderNames.ContentLength] = value.Value.ToString(CultureInfo.InvariantCulture);
793793
}
794794
else
795795
{
796-
headers.Remove(Constants.Headers.ContentLength);
796+
headers.Remove(HeaderNames.ContentLength);
797797
}
798798
}
799799
}

src/Microsoft.AspNet.Http.Core/RequestCookiesFeature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using Microsoft.AspNet.FeatureModel;
77
using Microsoft.AspNet.Http.Core.Collections;
88
using Microsoft.AspNet.Http.Core.Infrastructure;
9-
using Microsoft.AspNet.Http.Infrastructure;
109
using Microsoft.Framework.Internal;
10+
using Microsoft.Net.Http.Headers;
1111

1212
namespace Microsoft.AspNet.Http.Core
1313
{
@@ -44,7 +44,7 @@ public IReadableStringCollection Cookies
4444
}
4545

4646
var headers = _request.Fetch(_features).Headers;
47-
string cookiesHeader = ParsingHelpers.GetHeader(headers, Constants.Headers.Cookie) ?? string.Empty;
47+
string cookiesHeader = ParsingHelpers.GetHeader(headers, HeaderNames.Cookie) ?? string.Empty;
4848

4949
if (_cookiesCollection == null)
5050
{

src/Microsoft.Net.Http.Headers/HeaderNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static class HeaderNames
5454
public const string Vary = "Vary";
5555
public const string Via = "Via";
5656
public const string Warning = "Warning";
57+
public const string WebSocketSubProtocols = "Sec-WebSocket-Protocol";
5758
public const string WWWAuthenticate = "WWW-Authenticate";
5859
}
5960
}

0 commit comments

Comments
 (0)