@@ -142,7 +142,7 @@ public async Task<object> GetAsCacheVaryAsync(CachedVary cachedVary) {
142142 if ( index > - 1 ) {
143143 identityIsAcceptable = false ;
144144 // 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 ) ;
146146 if ( item != null ) {
147147 continue ;
148148 }
@@ -345,7 +345,7 @@ public bool IsResponseCacheable() {
345345 return false ;
346346 }
347347 return cache . VaryByContentEncodings . GetContentEncodings ( ) == null ||
348- IsCacheableEncoding ( _context . Response . ContentEncoding ,
348+ IsCacheableEncoding ( _context . Request . Headers [ HttpHeaders . AcceptEncoding ] ,
349349 cache . VaryByContentEncodings ) ;
350350 }
351351
@@ -633,13 +633,23 @@ private CacheItemPolicy GetCacheItemPolicy(CacheDependency dependency) {
633633 return cacheItemPolicy ;
634634 }
635635
636- private bool IsCacheableEncoding ( Encoding contentEncoding , HttpCacheVaryByContentEncodings varyByContentEncodings ) {
636+ private bool IsCacheableEncoding ( string headerContentEncodings , HttpCacheVaryByContentEncodings varyByContentEncodings ) {
637637 // return true if we are not varying by content encoding.
638638 if ( varyByContentEncodings == null ) {
639639 return true ;
640640 }
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 ;
643653 }
644654
645655 private bool ContainsNonShareableCookies ( ) {
@@ -948,9 +958,14 @@ private string CreateOutputCachedItemKey(string path, string verb, CachedVary ca
948958 if ( contentEncodings == null ) {
949959 return sb . ToString ( ) ;
950960 }
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+ }
954969 }
955970 // The key must end in "E", or the VaryByContentEncoding feature will break. Unfortunately,
956971 // 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) {
10731088 return true ;
10741089 }
10751090 }
1091+ return false ;
10761092 }
1077- return false ;
1093+ return true ;
10781094 }
10791095
10801096 private bool CheckIfModifiedSince ( HttpCachePolicySettings settings ) {
0 commit comments