Skip to content

Commit

Permalink
Merge branch 'release-3.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gardham-Pallister committed Feb 5, 2018
2 parents deac86f + 6ff8c1c commit ec7b4ff
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[![Build status](https://ci.appveyor.com/api/projects/status/r6sv51qx36sis1je?svg=true)](https://ci.appveyor.com/project/TomPallister/ocelot-fcfpb)

[![Windows Build history](https://buildstats.info/appveyor/chart/TomPallister/ocelot-fcfpb?branch=develop&includeBuildsFromPullRequest=false)](https://ci.appveyor.com/project/TomPallister/ocelot-fcfpb/history?branch=develop)


[![Coverage Status](https://coveralls.io/repos/github/TomPallister/Ocelot/badge.svg?branch=develop)](https://coveralls.io/github/TomPallister/Ocelot?branch=develop)

Ocelot is a .NET Api Gateway. This project is aimed at people using .NET running
Expand Down
2 changes: 2 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFi
var codePackage = packagesDir + File(artifacts["nuget"]);

Information("Pushing package " + codePackage);

Information("Calling NuGetPush");

NuGetPush(
codePackage,
Expand Down
4 changes: 2 additions & 2 deletions src/Ocelot/Responder/HttpContextResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task SetResponseOnHttpContext(HttpContext context, HttpResponseMess

using (Stream stream = new MemoryStream(content))
{
if (response.StatusCode != HttpStatusCode.NotModified)
if (response.StatusCode != HttpStatusCode.NotModified && context.Response.ContentLength != 0)
{
await stream.CopyToAsync(context.Response.Body);
}
Expand All @@ -79,4 +79,4 @@ private static void AddHeaderIfDoesntExist(HttpContext context, KeyValuePair<str
}
}
}
}
}
4 changes: 0 additions & 4 deletions test/Ocelot.UnitTests/Ocelot.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Responder\HttpContextResponderTests.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Ocelot\Ocelot.csproj" />
</ItemGroup>
Expand Down
64 changes: 64 additions & 0 deletions test/Ocelot.UnitTests/Responder/HttpContextResponderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Http;
using Ocelot.Headers;
using Ocelot.Responder;
using Shouldly;
using Xunit;

namespace Ocelot.UnitTests.Responder
{
public class HttpContextResponderTests
{
private readonly HttpContextResponder _responder;
private RemoveOutputHeaders _removeOutputHeaders;

public HttpContextResponderTests()
{
_removeOutputHeaders = new RemoveOutputHeaders();
_responder = new HttpContextResponder(_removeOutputHeaders);
}

[Fact]
public void should_remove_transfer_encoding_header()
{
var httpContext = new DefaultHttpContext();
var httpResponseMessage = new HttpResponseMessage {Content = new StringContent("")};
httpResponseMessage.Headers.Add("Transfer-Encoding", "woop");
_responder.SetResponseOnHttpContext(httpContext, httpResponseMessage).GetAwaiter().GetResult();
var header = httpContext.Response.Headers["Transfer-Encoding"];
header.ShouldBeEmpty();
}

[Fact]
public void should_have_content_length()
{
var httpContext = new DefaultHttpContext();
var httpResponseMessage = new HttpResponseMessage { Content = new StringContent("test") };
_responder.SetResponseOnHttpContext(httpContext, httpResponseMessage).GetAwaiter().GetResult();
var header = httpContext.Response.Headers["Content-Length"];
header.First().ShouldBe("4");
}

[Fact]
public void should_add_header()
{
var httpContext = new DefaultHttpContext();
var httpResponseMessage = new HttpResponseMessage { Content = new StringContent("test") };
httpResponseMessage.Headers.Add("test", "test");
_responder.SetResponseOnHttpContext(httpContext, httpResponseMessage).GetAwaiter().GetResult();
var header = httpContext.Response.Headers["test"];
header.First().ShouldBe("test");
}

[Fact]
public void should_call_without_exception()
{
var httpContext = new DefaultHttpContext();
_responder.SetErrorResponseOnContext(httpContext, 500);
}
}
}

0 comments on commit ec7b4ff

Please sign in to comment.