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

Commit 61b3aa2

Browse files
committed
React to HeaderUtilities update
1 parent 6e9ebc7 commit 61b3aa2

File tree

6 files changed

+23
-202
lines changed

6 files changed

+23
-202
lines changed

src/Microsoft.AspNetCore.ResponseCaching/Internal/CacheControlValues.cs

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

src/Microsoft.AspNetCore.ResponseCaching/Internal/HttpHeaderHelpers.cs

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

src/Microsoft.AspNetCore.ResponseCaching/Internal/ResponseCachingContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal DateTimeOffset? ResponseDate
6565
{
6666
_parsedResponseDate = true;
6767
DateTimeOffset date;
68-
if (HttpHeaderHelpers.TryParseDate(HttpContext.Response.Headers[HeaderNames.Date], out date))
68+
if (HeaderUtilities.TryParseDate(HttpContext.Response.Headers[HeaderNames.Date], out date))
6969
{
7070
_responseDate = date;
7171
}
@@ -92,7 +92,7 @@ internal DateTimeOffset? ResponseExpires
9292
{
9393
_parsedResponseExpires = true;
9494
DateTimeOffset expires;
95-
if (HttpHeaderHelpers.TryParseDate(HttpContext.Response.Headers[HeaderNames.Expires], out expires))
95+
if (HeaderUtilities.TryParseDate(HttpContext.Response.Headers[HeaderNames.Expires], out expires))
9696
{
9797
_responseExpires = expires;
9898
}
@@ -112,7 +112,7 @@ internal TimeSpan? ResponseSharedMaxAge
112112
if (!_parsedResponseSharedMaxAge)
113113
{
114114
_parsedResponseSharedMaxAge = true;
115-
HttpHeaderHelpers.TryParseTimeSpan(HttpContext.Response.Headers[HeaderNames.CacheControl], CacheControlValues.SharedMaxAgeString, out _responseSharedMaxAge);
115+
HeaderUtilities.TryParseTimeSpan(HttpContext.Response.Headers[HeaderNames.CacheControl], CacheControlHeaderValue.SharedMaxAgeString, out _responseSharedMaxAge);
116116
}
117117
return _responseSharedMaxAge;
118118
}
@@ -125,7 +125,7 @@ internal TimeSpan? ResponseMaxAge
125125
if (!_parsedResponseMaxAge)
126126
{
127127
_parsedResponseMaxAge = true;
128-
HttpHeaderHelpers.TryParseTimeSpan(HttpContext.Response.Headers[HeaderNames.CacheControl], CacheControlValues.MaxAgeString, out _responseMaxAge);
128+
HeaderUtilities.TryParseTimeSpan(HttpContext.Response.Headers[HeaderNames.CacheControl], CacheControlHeaderValue.MaxAgeString, out _responseMaxAge);
129129
}
130130
return _responseMaxAge;
131131
}

src/Microsoft.AspNetCore.ResponseCaching/Internal/ResponseCachingPolicyProvider.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public virtual bool IsRequestCacheable(ResponseCachingContext context)
3030
// Verify request cache-control parameters
3131
if (!StringValues.IsNullOrEmpty(request.Headers[HeaderNames.CacheControl]))
3232
{
33-
if (HttpHeaderHelpers.Contains(request.Headers[HeaderNames.CacheControl], CacheControlValues.NoCacheString))
33+
if (HeaderUtilities.Contains(request.Headers[HeaderNames.CacheControl], CacheControlHeaderValue.NoCacheString))
3434
{
3535
context.Logger.LogRequestWithNoCacheNotCacheable();
3636
return false;
@@ -40,7 +40,7 @@ public virtual bool IsRequestCacheable(ResponseCachingContext context)
4040
{
4141
// Support for legacy HTTP 1.0 cache directive
4242
var pragmaHeaderValues = request.Headers[HeaderNames.Pragma];
43-
if (HttpHeaderHelpers.Contains(request.Headers[HeaderNames.Pragma], CacheControlValues.NoCacheString))
43+
if (HeaderUtilities.Contains(request.Headers[HeaderNames.Pragma], CacheControlHeaderValue.NoCacheString))
4444
{
4545
context.Logger.LogRequestWithPragmaNoCacheNotCacheable();
4646
return false;
@@ -55,22 +55,22 @@ public virtual bool IsResponseCacheable(ResponseCachingContext context)
5555
var responseCacheControlHeader = context.HttpContext.Response.Headers[HeaderNames.CacheControl];
5656

5757
// Only cache pages explicitly marked with public
58-
if (!HttpHeaderHelpers.Contains(responseCacheControlHeader, CacheControlValues.PublicString))
58+
if (!HeaderUtilities.Contains(responseCacheControlHeader, CacheControlHeaderValue.PublicString))
5959
{
6060
context.Logger.LogResponseWithoutPublicNotCacheable();
6161
return false;
6262
}
6363

6464
// Check no-store
65-
if (HttpHeaderHelpers.Contains(context.HttpContext.Request.Headers[HeaderNames.CacheControl], CacheControlValues.NoStoreString)
66-
|| HttpHeaderHelpers.Contains(responseCacheControlHeader, CacheControlValues.NoStoreString))
65+
if (HeaderUtilities.Contains(context.HttpContext.Request.Headers[HeaderNames.CacheControl], CacheControlHeaderValue.NoStoreString)
66+
|| HeaderUtilities.Contains(responseCacheControlHeader, CacheControlHeaderValue.NoStoreString))
6767
{
6868
context.Logger.LogResponseWithNoStoreNotCacheable();
6969
return false;
7070
}
7171

7272
// Check no-cache
73-
if (HttpHeaderHelpers.Contains(responseCacheControlHeader, CacheControlValues.NoCacheString))
73+
if (HeaderUtilities.Contains(responseCacheControlHeader, CacheControlHeaderValue.NoCacheString))
7474
{
7575
context.Logger.LogResponseWithNoCacheNotCacheable();
7676
return false;
@@ -94,7 +94,7 @@ public virtual bool IsResponseCacheable(ResponseCachingContext context)
9494
}
9595

9696
// Check private
97-
if (HttpHeaderHelpers.Contains(responseCacheControlHeader, CacheControlValues.PrivateString))
97+
if (HeaderUtilities.Contains(responseCacheControlHeader, CacheControlHeaderValue.PrivateString))
9898
{
9999
context.Logger.LogResponseWithPrivateNotCacheable();
100100
return false;
@@ -159,15 +159,15 @@ public virtual bool IsCachedEntryFresh(ResponseCachingContext context)
159159

160160
// Add min-fresh requirements
161161
TimeSpan? minFresh;
162-
if (HttpHeaderHelpers.TryParseTimeSpan(requestCacheControlHeaders, CacheControlValues.MinFreshString, out minFresh))
162+
if (HeaderUtilities.TryParseTimeSpan(requestCacheControlHeaders, CacheControlHeaderValue.MinFreshString, out minFresh))
163163
{
164164
age += minFresh.Value;
165165
context.Logger.LogExpirationMinFreshAdded(minFresh.Value);
166166
}
167167

168168
// Validate shared max age, this overrides any max age settings for shared caches
169169
TimeSpan? cachedSharedMaxAge;
170-
HttpHeaderHelpers.TryParseTimeSpan(cachedCacheControlHeaders, CacheControlValues.SharedMaxAgeString, out cachedSharedMaxAge);
170+
HeaderUtilities.TryParseTimeSpan(cachedCacheControlHeaders, CacheControlHeaderValue.SharedMaxAgeString, out cachedSharedMaxAge);
171171

172172
if (age >= cachedSharedMaxAge)
173173
{
@@ -178,24 +178,24 @@ public virtual bool IsCachedEntryFresh(ResponseCachingContext context)
178178
else if (!cachedSharedMaxAge.HasValue)
179179
{
180180
TimeSpan? requestMaxAge;
181-
HttpHeaderHelpers.TryParseTimeSpan(requestCacheControlHeaders, CacheControlValues.MaxAgeString, out requestMaxAge);
181+
HeaderUtilities.TryParseTimeSpan(requestCacheControlHeaders, CacheControlHeaderValue.MaxAgeString, out requestMaxAge);
182182

183183
TimeSpan? cachedMaxAge;
184-
HttpHeaderHelpers.TryParseTimeSpan(cachedCacheControlHeaders, CacheControlValues.MaxAgeString, out cachedMaxAge);
184+
HeaderUtilities.TryParseTimeSpan(cachedCacheControlHeaders, CacheControlHeaderValue.MaxAgeString, out cachedMaxAge);
185185

186186
var lowestMaxAge = cachedMaxAge < requestMaxAge ? cachedMaxAge : requestMaxAge ?? cachedMaxAge;
187187
// Validate max age
188188
if (age >= lowestMaxAge)
189189
{
190190
// Must revalidate
191-
if (HttpHeaderHelpers.Contains(cachedCacheControlHeaders, CacheControlValues.MustRevalidateString))
191+
if (HeaderUtilities.Contains(cachedCacheControlHeaders, CacheControlHeaderValue.MustRevalidateString))
192192
{
193193
context.Logger.LogExpirationMustRevalidate(age, lowestMaxAge.Value);
194194
return false;
195195
}
196196

197197
TimeSpan? requestMaxStale;
198-
HttpHeaderHelpers.TryParseTimeSpan(requestCacheControlHeaders, CacheControlValues.MaxStaleString, out requestMaxStale);
198+
HeaderUtilities.TryParseTimeSpan(requestCacheControlHeaders, CacheControlHeaderValue.MaxStaleString, out requestMaxStale);
199199

200200
// Request allows stale values
201201
if (requestMaxStale.HasValue && age - lowestMaxAge < requestMaxStale)
@@ -211,7 +211,7 @@ public virtual bool IsCachedEntryFresh(ResponseCachingContext context)
211211
{
212212
// Validate expiration
213213
DateTimeOffset expires;
214-
if (HttpHeaderHelpers.TryParseDate(context.CachedResponseHeaders[HeaderNames.Expires], out expires) &&
214+
if (HeaderUtilities.TryParseDate(context.CachedResponseHeaders[HeaderNames.Expires], out expires) &&
215215
context.ResponseTime.Value >= expires)
216216
{
217217
context.Logger.LogExpirationExpiresExceeded(context.ResponseTime.Value, expires);

src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingMiddleware.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ internal async Task<bool> TryServeFromCacheAsync(ResponseCachingContext context)
198198
}
199199
}
200200

201-
if (HttpHeaderHelpers.Contains(context.HttpContext.Request.Headers[HeaderNames.CacheControl], CacheControlValues.OnlyIfCachedString))
201+
if (HeaderUtilities.Contains(context.HttpContext.Request.Headers[HeaderNames.CacheControl], CacheControlHeaderValue.OnlyIfCachedString))
202202
{
203203
_logger.LogGatewayTimeoutServed();
204204
context.HttpContext.Response.StatusCode = StatusCodes.Status504GatewayTimeout;
@@ -387,16 +387,14 @@ internal static bool ContentIsNotModified(ResponseCachingContext context)
387387
if (!StringValues.IsNullOrEmpty(ifUnmodifiedSince))
388388
{
389389
DateTimeOffset modified;
390-
if (!HttpHeaderHelpers.TryParseDate(cachedResponseHeaders[HeaderNames.LastModified], out modified))
390+
if (!HeaderUtilities.TryParseDate(cachedResponseHeaders[HeaderNames.LastModified], out modified) &&
391+
!HeaderUtilities.TryParseDate(cachedResponseHeaders[HeaderNames.Date], out modified))
391392
{
392-
if (!HttpHeaderHelpers.TryParseDate(cachedResponseHeaders[HeaderNames.Date], out modified))
393-
{
394-
return false;
395-
}
393+
return false;
396394
}
397395

398396
DateTimeOffset unmodifiedSince;
399-
if (HttpHeaderHelpers.TryParseDate(ifUnmodifiedSince, out unmodifiedSince) &&
397+
if (HeaderUtilities.TryParseDate(ifUnmodifiedSince, out unmodifiedSince) &&
400398
modified <= unmodifiedSince)
401399
{
402400
context.Logger.LogNotModifiedIfUnmodifiedSinceSatisfied(modified, unmodifiedSince);

test/Microsoft.AspNetCore.ResponseCaching.Tests/HttpHeaderHelpersTests.cs

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

0 commit comments

Comments
 (0)