@@ -142,7 +142,7 @@ public async Task<object> GetAsCacheVaryAsync(CachedVary cachedVary) {
142
142
if ( index > - 1 ) {
143
143
identityIsAcceptable = false ;
144
144
// the client Accept-Encoding header contains an encoding that's in the VaryByContentEncoding list
145
- item = await GetAsync ( key + contentEncodings [ index ] ) ;
145
+ item = await GetAsync ( key ) ;
146
146
if ( item != null ) {
147
147
continue ;
148
148
}
@@ -345,7 +345,7 @@ public bool IsResponseCacheable() {
345
345
return false ;
346
346
}
347
347
return cache . VaryByContentEncodings . GetContentEncodings ( ) == null ||
348
- IsCacheableEncoding ( _context . Response . ContentEncoding ,
348
+ IsCacheableEncoding ( _context . Request . Headers [ HttpHeaders . AcceptEncoding ] ,
349
349
cache . VaryByContentEncodings ) ;
350
350
}
351
351
@@ -633,13 +633,23 @@ private CacheItemPolicy GetCacheItemPolicy(CacheDependency dependency) {
633
633
return cacheItemPolicy ;
634
634
}
635
635
636
- private bool IsCacheableEncoding ( Encoding contentEncoding , HttpCacheVaryByContentEncodings varyByContentEncodings ) {
636
+ private bool IsCacheableEncoding ( string headerContentEncodings , HttpCacheVaryByContentEncodings varyByContentEncodings ) {
637
637
// return true if we are not varying by content encoding.
638
638
if ( varyByContentEncodings == null ) {
639
639
return true ;
640
640
}
641
- // return true if there is no Content-Encoding header or the Content-Encoding header is listed
642
- return contentEncoding == null || varyByContentEncodings . GetContentEncodings ( ) . Any ( varyByContentEncoding => varyByContentEncoding . Equals ( contentEncoding . ToString ( ) , StringComparison . OrdinalIgnoreCase ) ) ;
641
+ // return true if there is no Content-Encoding header
642
+ if ( headerContentEncodings == null ) {
643
+ return true ;
644
+ }
645
+ // return true if the Content-Encoding header is listed within varyByContentEncodings
646
+ string [ ] headerContentEncodingCollection = headerContentEncodings . Split ( new Char [ ] { ',' } ) ;
647
+ foreach ( string headerContentEncoding in headerContentEncodingCollection ) {
648
+ if ( varyByContentEncodings . GetContentEncodings ( ) . Any ( varyByContentEncoding => varyByContentEncoding . Equals ( headerContentEncoding , StringComparison . OrdinalIgnoreCase ) ) ) {
649
+ return true ;
650
+ }
651
+ }
652
+ return false ;
643
653
}
644
654
645
655
private bool ContainsNonShareableCookies ( ) {
@@ -948,9 +958,14 @@ private string CreateOutputCachedItemKey(string path, string verb, CachedVary ca
948
958
if ( contentEncodings == null ) {
949
959
return sb . ToString ( ) ;
950
960
}
951
- string coding = _context . Response . HeaderEncoding . ToString ( ) ;
952
- if ( contentEncodings . Any ( t => t . Equals ( coding , StringComparison . OrdinalIgnoreCase ) ) ) {
953
- sb . Append ( coding ) ;
961
+ if ( _context . Request . Headers [ HttpHeaders . AcceptEncoding ] != null ) {
962
+ string [ ] headerContentEncodingCollection = _context . Request . Headers [ HttpHeaders . AcceptEncoding ] . Split ( new char [ ] { ',' } ) ;
963
+ foreach ( string headerContentEncoding in headerContentEncodingCollection ) {
964
+ if ( contentEncodings . Any ( t => t . Equals ( headerContentEncoding , StringComparison . OrdinalIgnoreCase ) ) ) {
965
+ sb . Append ( headerContentEncoding ) ;
966
+ break ;
967
+ }
968
+ }
954
969
}
955
970
// The key must end in "E", or the VaryByContentEncoding feature will break. Unfortunately,
956
971
// there was no good way to encapsulate the logic within this routine. See the code in
@@ -1073,8 +1088,9 @@ private bool CheckIfNoneMatch(HttpCachePolicySettings settings) {
1073
1088
return true ;
1074
1089
}
1075
1090
}
1091
+ return false ;
1076
1092
}
1077
- return false ;
1093
+ return true ;
1078
1094
}
1079
1095
1080
1096
private bool CheckIfModifiedSince ( HttpCachePolicySettings settings ) {
0 commit comments