mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
parent
a9cfc04aa9
commit
26ae9948d5
@ -32,6 +32,15 @@ namespace Ocelot.Responder
|
||||
AddHeaderIfDoesntExist(context, httpResponseHeader);
|
||||
}
|
||||
|
||||
SetStatusCode(context, (int)response.StatusCode);
|
||||
|
||||
context.Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = response.ReasonPhrase;
|
||||
|
||||
if (response.Content is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var httpResponseHeader in response.Content.Headers)
|
||||
{
|
||||
AddHeaderIfDoesntExist(context, new Header(httpResponseHeader.Key, httpResponseHeader.Value));
|
||||
@ -44,10 +53,6 @@ namespace Ocelot.Responder
|
||||
AddHeaderIfDoesntExist(context, new Header("Content-Length", new []{ response.Content.Headers.ContentLength.ToString() }) );
|
||||
}
|
||||
|
||||
SetStatusCode(context, (int)response.StatusCode);
|
||||
|
||||
context.Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = response.ReasonPhrase;
|
||||
|
||||
using(content)
|
||||
{
|
||||
if (response.StatusCode != HttpStatusCode.NotModified && context.Response.ContentLength != 0)
|
||||
|
@ -39,6 +39,23 @@ namespace Ocelot.UnitTests.Responder
|
||||
header.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_ignore_content_if_null()
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
var response = new DownstreamResponse(null, HttpStatusCode.OK,
|
||||
new List<KeyValuePair<string, IEnumerable<string>>>(), "some reason");
|
||||
|
||||
Should.NotThrow(() =>
|
||||
{
|
||||
_responder
|
||||
.SetResponseOnHttpContext(httpContext, response)
|
||||
.GetAwaiter()
|
||||
.GetResult()
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_have_content_length()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user