mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 10:35:28 +08:00 
			
		
		
		
	fix for #214 and some tests for the class it was in but not for the error (cant be arsed to test as have to spin up IIS) (#218)
This commit is contained in:
		@@ -55,7 +55,7 @@ namespace Ocelot.Responder
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            using (Stream stream = new MemoryStream(content))
 | 
					            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);
 | 
					                    await stream.CopyToAsync(context.Response.Body);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,10 +19,6 @@
 | 
				
			|||||||
    <DebugSymbols>True</DebugSymbols>
 | 
					    <DebugSymbols>True</DebugSymbols>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <ItemGroup>
 | 
					 | 
				
			||||||
    <Compile Remove="Responder\HttpContextResponderTests.cs" />
 | 
					 | 
				
			||||||
  </ItemGroup>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <ProjectReference Include="..\..\src\Ocelot\Ocelot.csproj" />
 | 
					    <ProjectReference Include="..\..\src\Ocelot\Ocelot.csproj" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										64
									
								
								test/Ocelot.UnitTests/Responder/HttpContextResponderTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								test/Ocelot.UnitTests/Responder/HttpContextResponderTests.cs
									
									
									
									
									
										Normal file
									
								
							@@ -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);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user