messing around (#230)

This commit is contained in:
Tom Pallister
2018-02-13 23:00:41 +00:00
committed by GitHub
parent 947a1450d0
commit 6f177fbf5b
8 changed files with 163 additions and 9 deletions

View File

@ -6,13 +6,16 @@ namespace Ocelot.Cache
public class CachedResponse
{
public CachedResponse(
HttpStatusCode statusCode = HttpStatusCode.OK,
Dictionary<string, IEnumerable<string>> headers = null,
string body = null
HttpStatusCode statusCode,
Dictionary<string, IEnumerable<string>> headers,
string body,
Dictionary<string, IEnumerable<string>> contentHeaders
)
{
StatusCode = statusCode;
Headers = headers ?? new Dictionary<string, IEnumerable<string>>();
ContentHeaders = contentHeaders ?? new Dictionary<string, IEnumerable<string>>();
Body = body ?? "";
}
@ -20,6 +23,8 @@ namespace Ocelot.Cache
public Dictionary<string, IEnumerable<string>> Headers { get; private set; }
public Dictionary<string, IEnumerable<string>> ContentHeaders { get; private set; }
public string Body { get; private set; }
}
}

View File

@ -82,13 +82,21 @@ namespace Ocelot.Cache.Middleware
}
var response = new HttpResponseMessage(cached.StatusCode);
foreach (var header in cached.Headers)
{
response.Headers.Add(header.Key, header.Value);
}
var content = new MemoryStream(Convert.FromBase64String(cached.Body));
response.Content = new StreamContent(content);
foreach (var header in cached.ContentHeaders)
{
response.Content.Headers.Add(header.Key, header.Value);
}
return response;
}
@ -109,7 +117,10 @@ namespace Ocelot.Cache.Middleware
body = Convert.ToBase64String(content);
}
var cached = new CachedResponse(statusCode, headers, body);
var contentHeaders = response?.Content?.Headers.ToDictionary(v => v.Key, v => v.Value);
var cached = new CachedResponse(statusCode, headers, body, contentHeaders);
return cached;
}
}