Skip to content

Commit 29285da

Browse files
committed
Merge pull request filipw#142 from vdex42/dev
Fix bug when cache expires halfway during a request.
2 parents 37ab39a + 218fc90 commit 29285da

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/WebApi.OutputCache.V2/CacheOutputAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

test/WebApi.OutputCache.V2.Tests/ServerSideTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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
//{

0 commit comments

Comments
 (0)