File tree Expand file tree Collapse file tree
src/WebApi.OutputCache.V2
test/WebApi.OutputCache.V2.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -167,7 +167,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
167167 var val = _webApiCache . Get < byte [ ] > ( cachekey ) ;
168168 if ( val == null ) return ;
169169
170- var contenttype = _webApiCache . Get < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? new MediaTypeHeaderValue ( cachekey . Split ( new [ ] { ':' } , 2 ) [ 1 ] ) ;
170+ var contenttype = _webApiCache . Get < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? new MediaTypeHeaderValue ( cachekey . Split ( new [ ] { ':' } , 2 ) [ 1 ] . Split ( ';' ) [ 0 ] ) ;
171171
172172 actionContext . Response = actionContext . Request . CreateResponse ( ) ;
173173 actionContext . Response . Content = new ByteArrayContent ( val ) ;
Original file line number Diff line number Diff line change @@ -293,6 +293,19 @@ public void can_handle_ihttpactionresult_with_non_default_media_type()
293293 }
294294
295295
296+ [ Test ]
297+ public void can_handle_media_type_when_cache_has_expired_during_request ( )
298+ {
299+ var client = new HttpClient ( _server ) ;
300+ var req = new HttpRequestMessage ( HttpMethod . Get , _url + "Get_ihttpactionresult" ) ;
301+ req . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "text/xml" ) ) ;
302+ _cache . Setup ( o => o . Contains ( It . IsAny < string > ( ) ) ) . Returns ( true ) ;
303+ _cache . Setup ( o => o . Get < MediaTypeHeaderValue > ( It . Is ( ( string key ) => key . Contains ( Constants . ContentTypeKey ) ) ) ) . Returns ( ( MediaTypeHeaderValue ) null ) ;
304+ var result = client . SendAsync ( req ) . Result ;
305+ Assert . That ( result . IsSuccessStatusCode , Is . True ) ;
306+ }
307+
308+
296309 //[Test]
297310 //public void must_add_querystring_to_cache_params()
298311 //{
You can’t perform that action at this time.
0 commit comments