mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 18:22:49 +08:00
use a stream rather than byte array in responder (#519)
This commit is contained in:
parent
eb4b996c99
commit
b854ca63ce
@ -1,15 +1,14 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Ocelot.Configuration.Repository;
|
|
||||||
using Ocelot.Infrastructure.Extensions;
|
|
||||||
using Ocelot.Infrastructure.RequestData;
|
|
||||||
using Ocelot.Logging;
|
|
||||||
using Ocelot.Middleware;
|
|
||||||
|
|
||||||
namespace Ocelot.Errors.Middleware
|
namespace Ocelot.Errors.Middleware
|
||||||
{
|
{
|
||||||
using Configuration;
|
using Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Ocelot.Configuration.Repository;
|
||||||
|
using Ocelot.Infrastructure.Extensions;
|
||||||
|
using Ocelot.Infrastructure.RequestData;
|
||||||
|
using Ocelot.Logging;
|
||||||
|
using Ocelot.Middleware;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Catches all unhandled exceptions thrown by middleware, logs and returns a 500
|
/// Catches all unhandled exceptions thrown by middleware, logs and returns a 500
|
||||||
|
@ -36,7 +36,7 @@ namespace Ocelot.Responder
|
|||||||
AddHeaderIfDoesntExist(context, new Header(httpResponseHeader.Key, httpResponseHeader.Value));
|
AddHeaderIfDoesntExist(context, new Header(httpResponseHeader.Key, httpResponseHeader.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
var content = await response.Content.ReadAsByteArrayAsync();
|
var content = await response.Content.ReadAsStreamAsync();
|
||||||
|
|
||||||
AddHeaderIfDoesntExist(context, new Header("Content-Length", new []{ content.Length.ToString() }) );
|
AddHeaderIfDoesntExist(context, new Header("Content-Length", new []{ content.Length.ToString() }) );
|
||||||
|
|
||||||
@ -49,11 +49,11 @@ namespace Ocelot.Responder
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}, context);
|
}, context);
|
||||||
|
|
||||||
using (Stream stream = new MemoryStream(content))
|
using(content)
|
||||||
{
|
{
|
||||||
if (response.StatusCode != HttpStatusCode.NotModified && context.Response.ContentLength != 0)
|
if (response.StatusCode != HttpStatusCode.NotModified && context.Response.ContentLength != 0)
|
||||||
{
|
{
|
||||||
await stream.CopyToAsync(context.Response.Body);
|
await content.CopyToAsync(context.Response.Body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user