Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/WebApi.OutputCache.V2/CacheOutputAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,17 @@ public override void OnActionExecuting(HttpActionContext actionContext)
var val = _webApiCache.Get<byte[]>(cachekey);
if (val == null) return;

var contenttype = _webApiCache.Get<MediaTypeHeaderValue>(cachekey + Constants.ContentTypeKey) ?? new MediaTypeHeaderValue(cachekey.Split(new[] { ':' }, 2)[1].Split(';')[0]);
MediaTypeHeaderValue contentType;
var cachedContentType = _webApiCache.Get<string>(cachekey + Constants.ContentTypeKey);
if (!MediaTypeHeaderValue.TryParse(cachedContentType, out contentType))
{
contentType = new MediaTypeHeaderValue(cachekey.Split(new[] { ':' }, 2)[1].Split(';')[0]);
}

actionContext.Response = actionContext.Request.CreateResponse();
actionContext.Response.Content = new ByteArrayContent(val);

actionContext.Response.Content.Headers.ContentType = contenttype;
actionContext.Response.Content.Headers.ContentType = contentType;
var responseEtag = _webApiCache.Get<string>(cachekey + Constants.EtagKey);
if (responseEtag != null) SetEtag(actionContext.Response, responseEtag);

Expand Down Expand Up @@ -214,7 +219,7 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
if (responseContent != null)
{
var baseKey = config.MakeBaseCachekey(actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerType.FullName, actionExecutedContext.ActionContext.ActionDescriptor.ActionName);
var contentType = responseContent.Headers.ContentType;
var contentType = responseContent.Headers.ContentType.ToString();
string etag = actionExecutedContext.Response.Headers.ETag.Tag;
//ConfigureAwait false to avoid deadlocks
var content = await responseContent.ReadAsByteArrayAsync().ConfigureAwait(false);
Expand Down