mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:18:17 +08:00
messing around (#230)
This commit is contained in:
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user