@@ -30,22 +30,22 @@ void IHttpModule.Init(HttpApplication app) {
3030 public void Dispose ( ) { }
3131
3232 private IAsyncResult BeginOnResolveRequestCache ( object source , EventArgs e , AsyncCallback cb , object extraData ) {
33- return TaskAsyncHelper . BeginTask ( ( ) => OnEnter ( source , e ) , cb , extraData ) ;
33+ return TaskAsyncHelper . BeginTask ( ( ) => OnEnterAsync ( source , e ) , cb , extraData ) ;
3434 }
3535
3636 private static void EndOnResolveRequestCache ( IAsyncResult result ) {
3737 TaskAsyncHelper . EndTask ( result ) ;
3838 }
3939
4040 private IAsyncResult BeginOnUpdateRequestCache ( object source , EventArgs e , AsyncCallback cb , object extraData ) {
41- return TaskAsyncHelper . BeginTask ( ( ) => OnLeave ( source , e ) , cb , extraData ) ;
41+ return TaskAsyncHelper . BeginTask ( ( ) => OnLeaveAsync ( source , e ) , cb , extraData ) ;
4242 }
4343
4444 private static void EndOnUpdateRequestCache ( IAsyncResult result ) {
4545 TaskAsyncHelper . EndTask ( result ) ;
4646 }
4747
48- private async Task OnEnter ( object source , EventArgs eventArgs ) {
48+ private async Task OnEnterAsync ( object source , EventArgs eventArgs ) {
4949 var app = ( HttpApplication ) source ;
5050 HttpContext context = app . Context ;
5151 HttpRequest request = context . Request ;
@@ -56,7 +56,7 @@ private async Task OnEnter(object source, EventArgs eventArgs) {
5656 }
5757
5858 // Create a lookup key. Also store the key in global parameter _key to be used inside OnLeave() later
59- string key = _key = await OutputCacheHelper . CreateOutputCachedItemKey ( context , null ) ;
59+ string key = _key = await OutputCacheHelper . CreateOutputCachedItemKeyAsync ( context , null ) ;
6060
6161 // Lookup the cache vary using the key
6262 object item = await _outputCacheHelper . Get ( key ) ;
@@ -98,7 +98,7 @@ private async Task OnEnter(object source, EventArgs eventArgs) {
9898 app . CompleteRequest ( ) ;
9999 }
100100
101- private async Task OnLeave ( object source , EventArgs eventArgs ) {
101+ private async Task OnLeaveAsync ( object source , EventArgs eventArgs ) {
102102 HttpContext context = ( ( HttpApplication ) source ) . Context ;
103103 HttpRequest request = context . Request ;
104104 HttpResponse response = context . Response ;
@@ -172,7 +172,7 @@ private async Task CacheResponse(HttpContext context, HttpResponse response) {
172172 string [ ] varyByParams = settings . IgnoreParams ? null : settings . VaryByParams ;
173173 /* Create the key if it was not created in OnEnter */
174174 if ( _key == null ) {
175- _key = await OutputCacheHelper . CreateOutputCachedItemKey ( context , null ) ;
175+ _key = await OutputCacheHelper . CreateOutputCachedItemKeyAsync ( context , null ) ;
176176 Debug . Assert ( _key != null , "_key != null" ) ;
177177 }
178178 if ( settings . VaryByContentEncodings == null && varyByHeaders == null && varyByParams == null &&
@@ -215,7 +215,7 @@ private async Task CacheResponse(HttpContext context, HttpResponse response) {
215215 VaryByAllParams = varyByAllParams ,
216216 VaryByCustom = settings . VaryByCustom
217217 } ;
218- keyRawResponse = await OutputCacheHelper . CreateOutputCachedItemKey ( context , cachedVary ) ;
218+ keyRawResponse = await OutputCacheHelper . CreateOutputCachedItemKeyAsync ( context , cachedVary ) ;
219219 if ( keyRawResponse == null ) {
220220 Debug . WriteLine ( "OutputCacheModuleLeave" , "Couldn't add non-cacheable post.\n \t key=" + _key ) ;
221221 return ;
@@ -327,6 +327,9 @@ private static void GetCachedResponse(HttpContext context, HttpRequest request,
327327 */
328328 Debug . WriteLine ( "OutputCacheModuleEnter" , "Hit, conditional request satisfied, status=304. Key=" + key +
329329 ". Returning from OutputCacheModule::Enter" ) ;
330+ if ( response . HeadersWritten ) {
331+ response . ClearHeaders ( ) ;
332+ }
330333 response . Clear ( ) ;
331334 response . StatusCode = 304 ;
332335 }
@@ -361,14 +364,14 @@ private async Task<bool> CheckHeadersToDetermineAcceptCachedCopy(string key, Htt
361364 string [ ] cacheDirectives = request . Headers [ "Cache-Control" ] . Split ( s_fieldSeparators ) ;
362365 foreach ( string directive in cacheDirectives ) {
363366 if ( directive == "no-cache" || directive == "no-store" ) {
364- Debug . WriteLine ( "OutputCacheModuleEnter " ,
367+ Debug . WriteLine ( "OutputCache Module Async Enter " ,
365368 "Skipping lookup because of Cache-Control: no-cache or no-store directive. Returning from OutputCacheModule::Enter" ) ;
366369 return true ;
367370 }
368371 if ( directive . StartsWith ( "max-age=" ) ) {
369372 int maxage ;
370373 try {
371- maxage = Convert . ToInt32 ( directive . Substring ( 8 ) , CultureInfo . InvariantCulture ) ;
374+ int . TryParse ( directive . Substring ( 8 ) , out maxage ) ;
372375 }
373376 catch {
374377 maxage = - 1 ;
@@ -494,7 +497,7 @@ private async Task<CachedItem> CheckCacheVaryAsync(CachedVary cachedVary, HttpCo
494497 *
495498 * Skip this step if it's a VaryByNone vary policy.
496499 */
497- string key = await OutputCacheHelper . CreateOutputCachedItemKey ( context , cachedVary ) ;
500+ string key = await OutputCacheHelper . CreateOutputCachedItemKeyAsync ( context , cachedVary ) ;
498501 if ( key == null ) {
499502 Debug . WriteLine ( "OutputCacheModuleEnter" ,
500503 "Miss, key could not be created for vary-by item. Returning from OutputCacheModule::Enter" ) ;
0 commit comments