Skip to content

Commit 53fc45e

Browse files
committed
fix http headers and remove httpcontextbase
fix http headers and remove httpcontextbase
1 parent fbeba28 commit 53fc45e

9 files changed

Lines changed: 1016 additions & 1029 deletions

src/OutputCacheModuleAsync/CacheDirectives.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Microsoft.AspNet.OutputCache {
22

3-
static class CacheDirectives {
3+
sealed class CacheDirectives {
44
public const string NoCache = "no-cache";
55
public const string NoStore = "no-store";
66
public const string MaxAge = "max-age=";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Microsoft.AspNet.OutputCache {
2+
sealed class HttpHeaders {
3+
public const string IfModifiedSince = "If-Modified-Since";
4+
public const string IfNoneMatch = "If-None-Match";
5+
public const string AcceptEncoding = "Accept-Encoding";
6+
public const string ContentEncoding = "Content-Encoding";
7+
public const string CacheControl = "Cache-Control";
8+
public const string Pragma = "Pragma";
9+
public const string Range = "Range";
10+
public const string Server = "Server";
11+
public const string SetCookie = "Set-Cookie";
12+
public const string Expires = "Expires";
13+
public const string LastModified = "Last-Modified";
14+
public const string Etag = "ETag";
15+
public const string Vary = "Vary";
16+
}
17+
}

src/OutputCacheModuleAsync/HttpMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace Microsoft.AspNet.OutputCache {
2-
static class HttpMethods {
2+
sealed class HttpMethods {
33
public const string POST = "POST";
44
public const string HEAD = "HEAD";
55
public const string GET = "GET";

src/OutputCacheModuleAsync/HttpRequestHeaders.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/OutputCacheModuleAsync/Microsoft.AspNet.OutputCache.OutputCacheModuleAsync.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<Compile Include="CachedVary.cs" />
5555
<Compile Include="HttpMethods.cs" />
5656
<Compile Include="CacheDirectives.cs" />
57-
<Compile Include="HttpRequestHeaders.cs" />
57+
<Compile Include="HttpHeaders.cs" />
5858
<Compile Include="InMemoryOutputCacheProvider.cs" />
5959
<Compile Include="DependencyCacheEntry.cs" />
6060
<Compile Include="CachedRawResponse.cs" />

src/OutputCacheModuleAsync/OutputCacheHelper.cs

Lines changed: 918 additions & 927 deletions
Large diffs are not rendered by default.

src/OutputCacheModuleAsync/OutputCacheModuleAsync.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ private static void EndOnUpdateRequestCache(IAsyncResult result) {
4242

4343
private async Task OnEnterAsync(object source, EventArgs eventArgs) {
4444
var app = (HttpApplication)source;
45-
var outputCacheHelper = new OutputCacheHelper(new HttpContextWrapper(app.Context));
46-
if (!outputCacheHelper.IsHttpMethodSupported()) {
45+
var helper = new OutputCacheHelper(app.Context);
46+
if (!helper.IsHttpMethodSupported()) {
4747
return;
4848
}
4949

5050
// Create a lookup key. Also store the key in global parameter _key to be used inside OnLeave() later
51-
string key = outputCacheHelper.CreateOutputCachedItemKey(null);
51+
string key = helper.CreateOutputCachedItemKey(null);
5252

5353
// Lookup the cache vary using the key
54-
object item = await outputCacheHelper.GetAsync(key);
54+
object item = await helper.GetAsync(key);
5555
if (item == null) {
5656
return;
5757
}
@@ -63,7 +63,7 @@ private async Task OnEnterAsync(object source, EventArgs eventArgs) {
6363
object cachedItem = null;
6464
var cachedVary = item as CachedVary;
6565
if (cachedVary != null) {
66-
cachedItem = await outputCacheHelper.GetAsCacheVaryAsync(cachedVary);
66+
cachedItem = await helper.GetAsCacheVaryAsync(cachedVary);
6767
}
6868
if (cachedItem == null) {
6969
return;
@@ -72,22 +72,22 @@ private async Task OnEnterAsync(object source, EventArgs eventArgs) {
7272
// From this point on, we have an Raw Response entry to work with.
7373
var cachedRawResponse = (CachedRawResponse)cachedItem;
7474
HttpCachePolicySettings settings = cachedRawResponse.CachePolicy;
75-
if (outputCacheHelper.CheckCachedVary(cachedVary, settings)) {
75+
if (helper.CheckCachedVary(cachedVary, settings)) {
7676
return;
7777
}
78-
if (settings.IgnoreRangeRequests && outputCacheHelper.IsRangeRequest()) {
78+
if (settings.IgnoreRangeRequests && helper.IsRangeRequest()) {
7979
return;
8080
}
81-
if (outputCacheHelper.CheckHeaders(settings)) {
81+
if (helper.CheckHeaders(settings)) {
8282
return;
8383
}
84-
if (await outputCacheHelper.CheckValidityAsync(key, settings)) {
84+
if (await helper.CheckValidityAsync(key, settings)) {
8585
return;
8686
}
87-
if (!outputCacheHelper.IsContentEncodingAcceptable(cachedVary, cachedRawResponse.RawResponse)) {
87+
if (!helper.IsContentEncodingAcceptable(cachedVary, cachedRawResponse.RawResponse)) {
8888
return;
8989
}
90-
outputCacheHelper.UpdateCachedResponse(settings, cachedRawResponse.RawResponse);
90+
helper.UpdateCachedResponse(settings, cachedRawResponse.RawResponse);
9191

9292
//Re-insert entry in kernel cache if necessary
9393
string originalCacheUrl = cachedRawResponse.KernelCacheUrl;
@@ -100,9 +100,9 @@ private async Task OnEnterAsync(object source, EventArgs eventArgs) {
100100
}
101101

102102
private async Task OnLeaveAsync(object source, EventArgs eventArgs) {
103-
var outputCacheHelper = new OutputCacheHelper(new HttpContextWrapper(((HttpApplication)source).Context));
104-
if (outputCacheHelper.IsResponseCacheable()) {
105-
await outputCacheHelper.CacheResponseAsync();
103+
var helper = new OutputCacheHelper(((HttpApplication)source).Context);
104+
if (helper.IsResponseCacheable()) {
105+
await helper.CacheResponseAsync();
106106
}
107107
}
108108
}

src/OutputCacheModuleAsync/TaskWrapperAsyncResults.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading;
55

66
// Wraps a Task class, optionally overriding the State object (since the Task Asynchronous Pattern doesn't normally use them).
7-
class TaskWrapperAsyncResult : IAsyncResult {
7+
sealed class TaskWrapperAsyncResult : IAsyncResult {
88
private bool _forceCompletedSynchronously;
99

1010
public TaskWrapperAsyncResult(Task task, object asyncState) {

src/OutputCacheModuleAsync/Util.cs

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public int Compare(object a, object b) {
2121
}
2222
}
2323

24-
class CryptoUtil {
24+
static class CryptoUtil {
2525
/// <summary>
2626
/// Computes the SHA256 hash of a given input.
2727
/// </summary>
@@ -50,27 +50,13 @@ public static byte[] ComputeHash(byte[] buffer, int offset, int count) {
5050
}
5151
}
5252

53-
class HttpDate {
53+
static class HttpDate {
5454
private static readonly int[] s_tensDigit = { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 };
55-
56-
private static int Atoi2(string s, int startIndex) {
57-
try {
58-
int tens = s[0 + startIndex] - '0';
59-
int ones = s[1 + startIndex] - '0';
60-
61-
return s_tensDigit[tens] + ones;
62-
}
63-
catch {
64-
throw new FormatException("Atio2Badstring");
65-
}
66-
}
67-
6855
private static readonly string[] s_months = {
6956
"Jan", "Feb", "Mar", "Apr",
7057
"May", "Jun", "Jul", "Aug",
7158
"Sep", "Oct", "Nov", "Dec"
7259
};
73-
7460
// Custom table for make_month() for mapping "Apr" to 4
7561
private static readonly sbyte[] s_monthIndexTable = {
7662
-1, (sbyte) 'A', 2, 12, -1, -1, -1, 8, // A to G
@@ -82,54 +68,7 @@ private static int Atoi2(string s, int startIndex) {
8268
9, -1, (sbyte) 'R', -1, 10, -1, 11, -1, // p to w
8369
-1, 5, -1, -1, -1, -1, -1, -1 // x to z
8470
};
85-
86-
private static int make_month(string s, int startIndex) {
87-
//
88-
// use the third character as the index
89-
//
90-
int i = (s[2 + startIndex] - 0x40) & 0x3F;
91-
sbyte monthIndex = s_monthIndexTable[i];
92-
if (monthIndex >= 13) {
93-
//
94-
// ok, we need to look at the second character
95-
//
96-
switch (monthIndex) {
97-
case (sbyte)'N':
98-
//
99-
// we got an N which we need to resolve further
100-
//
101-
//
102-
// if s[1] is 'u' then Jun, if 'a' then Jan
103-
//
104-
monthIndex =
105-
(sbyte)(s_monthIndexTable[(s[1 + startIndex] - 0x40) & 0x3f] == (sbyte)'A' ? 1 : 6);
106-
break;
107-
case (sbyte)'R':
108-
//
109-
// if s[1] is 'a' then March, if 'p' then April
110-
//
111-
monthIndex =
112-
(sbyte)(s_monthIndexTable[(s[1 + startIndex] - 0x40) & 0x3f] == (sbyte)'A' ? 3 : 4);
113-
break;
114-
default:
115-
throw new FormatException("MakeMonthBadstring");
116-
}
117-
}
118-
string monthstring = s_months[monthIndex - 1];
119-
if ((s[0 + startIndex] == monthstring[0]) &&
120-
(s[1 + startIndex] == monthstring[1]) &&
121-
(s[2 + startIndex] == monthstring[2])) {
122-
return (monthIndex);
123-
}
124-
if ((char.ToUpper(s[0 + startIndex], CultureInfo.InvariantCulture) == monthstring[0]) &&
125-
(char.ToLower(s[1 + startIndex], CultureInfo.InvariantCulture) == monthstring[1]) &&
126-
(char.ToLower(s[2 + startIndex], CultureInfo.InvariantCulture) == monthstring[2])) {
127-
return monthIndex;
128-
}
129-
throw new FormatException("MakeMonthBadstring");
130-
}
131-
132-
public static DateTime UtcParse(string time) {
71+
public static DateTime UtcParse(string time) {
13372
int i;
13473
int year, month, day, hour, minute, second;
13574
if (time == null) {
@@ -190,9 +129,67 @@ public static DateTime UtcParse(string time) {
190129
}
191130
return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc);
192131
}
193-
}
194132

195-
class StringUtil {
133+
private static int Atoi2(string s, int startIndex) {
134+
try {
135+
int tens = s[0 + startIndex] - '0';
136+
int ones = s[1 + startIndex] - '0';
137+
138+
return s_tensDigit[tens] + ones;
139+
}
140+
catch {
141+
throw new FormatException("Atio2Badstring");
142+
}
143+
}
144+
145+
private static int make_month(string s, int startIndex) {
146+
//
147+
// use the third character as the index
148+
//
149+
int i = (s[2 + startIndex] - 0x40) & 0x3F;
150+
sbyte monthIndex = s_monthIndexTable[i];
151+
if (monthIndex >= 13) {
152+
//
153+
// ok, we need to look at the second character
154+
//
155+
switch (monthIndex) {
156+
case (sbyte)'N':
157+
//
158+
// we got an N which we need to resolve further
159+
//
160+
//
161+
// if s[1] is 'u' then Jun, if 'a' then Jan
162+
//
163+
monthIndex =
164+
(sbyte)(s_monthIndexTable[(s[1 + startIndex] - 0x40) & 0x3f] == (sbyte)'A' ? 1 : 6);
165+
break;
166+
case (sbyte)'R':
167+
//
168+
// if s[1] is 'a' then March, if 'p' then April
169+
//
170+
monthIndex =
171+
(sbyte)(s_monthIndexTable[(s[1 + startIndex] - 0x40) & 0x3f] == (sbyte)'A' ? 3 : 4);
172+
break;
173+
default:
174+
throw new FormatException("MakeMonthBadstring");
175+
}
176+
}
177+
string monthstring = s_months[monthIndex - 1];
178+
if ((s[0 + startIndex] == monthstring[0]) &&
179+
(s[1 + startIndex] == monthstring[1]) &&
180+
(s[2 + startIndex] == monthstring[2])) {
181+
return (monthIndex);
182+
}
183+
if ((char.ToUpper(s[0 + startIndex], CultureInfo.InvariantCulture) == monthstring[0]) &&
184+
(char.ToLower(s[1 + startIndex], CultureInfo.InvariantCulture) == monthstring[1]) &&
185+
(char.ToLower(s[2 + startIndex], CultureInfo.InvariantCulture) == monthstring[2])) {
186+
return monthIndex;
187+
}
188+
throw new FormatException("MakeMonthBadstring");
189+
}
190+
}
191+
192+
static class StringUtil {
196193
public static bool StringArrayEquals(string[] a, string[] b) {
197194
if ((a == null) != (b == null)) {
198195
return false;

0 commit comments

Comments
 (0)