This repository was archived by the owner on Nov 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-14
lines changed
src/Microsoft.AspNetCore.ResponseCaching
test/Microsoft.AspNetCore.ResponseCaching.Tests Expand file tree Collapse file tree 2 files changed +44
-14
lines changed Original file line number Diff line number Diff line change 44using System ;
55using System . IO ;
66using System . Globalization ;
7+ using System . Linq ;
78using System . Text ;
89using System . Threading . Tasks ;
910using Microsoft . AspNetCore . Http ;
@@ -178,25 +179,39 @@ internal string CreateCacheKey(CachedVaryBy varyBy)
178179 }
179180 }
180181
181- // Vary by params
182+ // Vary by query params
182183 if ( varyBy ? . Params . Count > 0 )
183184 {
184- // TODO: resolve key format and delimiters
185- foreach ( var param in varyBy . Params )
185+ if ( varyBy . Params . Count == 1 && string . Equals ( varyBy . Params [ 0 ] , "*" , StringComparison . OrdinalIgnoreCase ) )
186186 {
187- // TODO: Normalization of order, case?
188- var value = _httpContext . Request . Query [ param ] ;
189-
190- // TODO: How to handle null/empty string?
191- if ( StringValues . IsNullOrEmpty ( value ) )
187+ // Vary by all available query params
188+ foreach ( var query in _httpContext . Request . Query . OrderBy ( q => q . Key ) )
192189 {
193- value = "null" ;
190+ builder . Append ( ";" )
191+ . Append ( query . Key )
192+ . Append ( "=" )
193+ . Append ( query . Value ) ;
194+ }
195+ }
196+ else
197+ {
198+ // TODO: resolve key format and delimiters
199+ foreach ( var param in varyBy . Params )
200+ {
201+ // TODO: Normalization of order, case?
202+ var value = _httpContext . Request . Query [ param ] ;
203+
204+ // TODO: How to handle null/empty string?
205+ if ( StringValues . IsNullOrEmpty ( value ) )
206+ {
207+ value = "null" ;
208+ }
209+
210+ builder . Append ( ";" )
211+ . Append ( param )
212+ . Append ( "=" )
213+ . Append ( value ) ;
194214 }
195-
196- builder . Append ( ";" )
197- . Append ( param )
198- . Append ( "=" )
199- . Append ( value ) ;
200215 }
201216 }
202217
Original file line number Diff line number Diff line change @@ -205,6 +205,21 @@ public void CreateCacheKey_Includes_ListedVaryByParamsOnly()
205205 } ) ) ;
206206 }
207207
208+ [ Fact ]
209+ public void CreateCacheKey_Includes_AllQueryParamsGivenAsterisk ( )
210+ {
211+ var httpContext = new DefaultHttpContext ( ) ;
212+ httpContext . Request . Method = "GET" ;
213+ httpContext . Request . Path = "/" ;
214+ httpContext . Request . QueryString = new QueryString ( "?ParamA=ValueA&ParamB=ValueB" ) ;
215+ var context = CreateTestContext ( httpContext ) ;
216+
217+ Assert . Equal ( "GET;/;ParamA=ValueA;ParamB=ValueB" , context . CreateCacheKey ( new CachedVaryBy ( )
218+ {
219+ Params = new string [ ] { "*" }
220+ } ) ) ;
221+ }
222+
208223 [ Fact ]
209224 public void CreateCacheKey_Includes_ListedVaryByHeadersAndParams ( )
210225 {
You can’t perform that action at this time.
0 commit comments