diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e2bff19..2a4d38568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.0.4.7 (19 July 2018) + + - [#148](https://github.com/WireMock-Net/WireMock.Net/issues/148) - Question: proxy passthrough when no match? + +Commits: f1896ef73a...72394b6d3e + + # 1.0.4.6 (18 July 2018) - [#168](https://github.com/WireMock-Net/WireMock.Net/pull/168) - Expose scenario states contributed by Stef Heyenrath ([StefH](https://github.com/StefH)) +feature diff --git a/GitReleaseNotes.txt b/GitReleaseNotes.txt index b5144fbcc..b3eccff44 100644 --- a/GitReleaseNotes.txt +++ b/GitReleaseNotes.txt @@ -1,5 +1,5 @@ https://github.com/GitTools/GitReleaseNotes -GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.4.6 +GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.4.7 GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags diff --git a/WireMock.Net Solution.sln b/WireMock.Net Solution.sln index b61627214..dcba3a99b 100644 --- a/WireMock.Net Solution.sln +++ b/WireMock.Net Solution.sln @@ -52,6 +52,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.StandAlone.Net EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Service", "examples\Wiremock.Net.Service\WireMock.Net.Service.csproj", "{7F0B2446-0363-4720-AF46-F47F83B557DC}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.HeadersTest", "examples\WireMock.Net.Console.HeadersTest\WireMock.Net.Console.HeadersTest.csproj", "{B70278E7-A2C6-4A3B-BBA9-1C873CA6F03C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -114,6 +116,10 @@ Global {7F0B2446-0363-4720-AF46-F47F83B557DC}.Debug|Any CPU.Build.0 = Debug|Any CPU {7F0B2446-0363-4720-AF46-F47F83B557DC}.Release|Any CPU.ActiveCfg = Release|Any CPU {7F0B2446-0363-4720-AF46-F47F83B557DC}.Release|Any CPU.Build.0 = Release|Any CPU + {B70278E7-A2C6-4A3B-BBA9-1C873CA6F03C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B70278E7-A2C6-4A3B-BBA9-1C873CA6F03C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B70278E7-A2C6-4A3B-BBA9-1C873CA6F03C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B70278E7-A2C6-4A3B-BBA9-1C873CA6F03C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -133,6 +139,7 @@ Global {23A9AA3C-40FC-42AA-8A5E-05899795A1C6} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} {3C279524-DB73-4DE3-BEF1-F2B2958C9F65} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} {7F0B2446-0363-4720-AF46-F47F83B557DC} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} + {B70278E7-A2C6-4A3B-BBA9-1C873CA6F03C} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BF428BCC-C837-433B-87D2-15C7014B73E9} diff --git a/examples/WireMock.Net.Console.HeadersTest/Program.cs b/examples/WireMock.Net.Console.HeadersTest/Program.cs new file mode 100644 index 000000000..ea8480ba3 --- /dev/null +++ b/examples/WireMock.Net.Console.HeadersTest/Program.cs @@ -0,0 +1,60 @@ +using System.IO; +using System.Reflection; +using log4net; +using log4net.Config; +using log4net.Repository; +using Newtonsoft.Json; +using WireMock.Logging; +using WireMock.RequestBuilders; +using WireMock.ResponseBuilders; +using WireMock.Server; +using WireMock.Settings; + +namespace WireMock.Net.Console.NETCoreApp +{ + static class Program + { + private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); + private static readonly ILog Log = LogManager.GetLogger(typeof(Program)); + + static void Main(params string[] args) + { + XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config")); + + string url = "http://localhost:9999/"; + + var server = FluentMockServer.Start(new FluentMockServerSettings + { + Urls = new[] { url }, + StartAdminInterface = true, + Logger = new WireMockConsoleLogger() + }); + System.Console.WriteLine("FluentMockServer listening at {0}", string.Join(",", server.Urls)); + + server.SetBasicAuthentication("a", "b"); + + server.AllowPartialMapping(); + + server + .Given(Request.Create() + .UsingGet() + .WithHeader("Keep-Alive-Test", "stef") + ) + .RespondWith(Response.Create() + .WithHeader("Keep-Alive", "timeout=1, max=1") + .WithBody("Keep-Alive OK") + ); + + System.Console.WriteLine("Press any key to stop the server"); + System.Console.ReadKey(); + server.Stop(); + + System.Console.WriteLine("Displaying all requests"); + var allRequests = server.LogEntries; + System.Console.WriteLine(JsonConvert.SerializeObject(allRequests, Formatting.Indented)); + + System.Console.WriteLine("Press any key to quit"); + System.Console.ReadKey(); + } + } +} \ No newline at end of file diff --git a/examples/WireMock.Net.Console.HeadersTest/WireMock.Net.Console.HeadersTest.csproj b/examples/WireMock.Net.Console.HeadersTest/WireMock.Net.Console.HeadersTest.csproj new file mode 100644 index 000000000..7d8f16e38 --- /dev/null +++ b/examples/WireMock.Net.Console.HeadersTest/WireMock.Net.Console.HeadersTest.csproj @@ -0,0 +1,24 @@ + + + + Exe + netcoreapp1.1 + ../../WireMock.Net-Logo.ico + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + + \ No newline at end of file diff --git a/examples/WireMock.Net.Console.HeadersTest/log4net.config b/examples/WireMock.Net.Console.HeadersTest/log4net.config new file mode 100644 index 000000000..feae99529 --- /dev/null +++ b/examples/WireMock.Net.Console.HeadersTest/log4net.config @@ -0,0 +1,20 @@ + + + +
+ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/WireMock.Net.Console.HeadersTest/nlog.config b/examples/WireMock.Net.Console.HeadersTest/nlog.config new file mode 100644 index 000000000..de6d9072a --- /dev/null +++ b/examples/WireMock.Net.Console.HeadersTest/nlog.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/WireMock.Net.ConsoleApplication/MainApp.cs b/examples/WireMock.Net.ConsoleApplication/MainApp.cs index dd33505ef..e34551127 100644 --- a/examples/WireMock.Net.ConsoleApplication/MainApp.cs +++ b/examples/WireMock.Net.ConsoleApplication/MainApp.cs @@ -38,6 +38,25 @@ public static void Run() server.AllowPartialMapping(); + server + .Given(Request.Create() + .UsingGet() + .WithPath("/proxy-test-keep-alive") + ) + .RespondWith(Response.Create() + .WithHeader("Keep-Alive", "timeout=1, max=1") + ); + + server + .Given(Request.Create() + .UsingGet() + .WithPath("/proxy-execute-keep-alive") + ) + .RespondWith(Response.Create() + .WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999", BlackListedHeaders = new [] { "Keep-Alive" } }) + .WithHeader("Keep-Alive-Test", "stef") + ); + server .Given(Request.Create() .WithPath("/xpath").UsingPost() diff --git a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj index 18a51b105..6da4d57c5 100644 --- a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj +++ b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj @@ -3,7 +3,7 @@ Lightweight StandAlone Http Mocking Server for .Net. WireMock.Net.StandAlone - 1.0.4.6 + 1.0.4.7 Stef Heyenrath net452;net46;netstandard1.3;netstandard2.0 true diff --git a/src/WireMock.Net/Owin/OwinResponseMapper.cs b/src/WireMock.Net/Owin/OwinResponseMapper.cs index 85e3f627d..f266446dc 100644 --- a/src/WireMock.Net/Owin/OwinResponseMapper.cs +++ b/src/WireMock.Net/Owin/OwinResponseMapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; @@ -49,8 +50,13 @@ public class OwinResponseMapper else { #if !NETSTANDARD - response.Headers.AppendValues(pair.Key, pair.Value.ToArray()); + // For non-NETSTANDARD, check if this response header can be added (#148) + if (!WebHeaderCollection.IsRestricted(pair.Key, true)) + { + response.Headers.AppendValues(pair.Key, pair.Value.ToArray()); + } #else + // NETSTANDARD can add any header (or so it seems) response.Headers.Append(pair.Key, pair.Value.ToArray()); #endif } diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj index 19f5a0e17..2dc2e0558 100644 --- a/src/WireMock.Net/WireMock.Net.csproj +++ b/src/WireMock.Net/WireMock.Net.csproj @@ -3,7 +3,7 @@ Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape. WireMock.Net - 1.0.4.6 + 1.0.4.7 Stef Heyenrath net452;net46;netstandard1.3;netstandard2.0 true @@ -50,13 +50,13 @@ - + - + @@ -65,7 +65,7 @@ - + diff --git a/test/WireMock.Net.Tests/FluentMockServerTests.cs b/test/WireMock.Net.Tests/FluentMockServerTests.cs index db3cf277c..9b45208da 100644 --- a/test/WireMock.Net.Tests/FluentMockServerTests.cs +++ b/test/WireMock.Net.Tests/FluentMockServerTests.cs @@ -585,6 +585,24 @@ public async Task FluentMockServer_Should_respond_to_request_callback() Check.That(response).IsEqualTo("/fooBar"); } + + [Fact] + public async Task FluentMockServer_Should_exclude_restrictedResponseHeader_for_IOwinResponse() + { + _server = FluentMockServer.Start(); + + _server + .Given(Request.Create().WithPath("/foo").UsingGet()) + .RespondWith(Response.Create().WithHeader("Keep-Alive", "").WithHeader("test", "")); + + // Act + var response = await new HttpClient().GetAsync("http://localhost:" + _server.Ports[0] + "/foo"); + + // Assert + Check.That(response.Headers.Contains("test")).IsTrue(); + Check.That(response.Headers.Contains("Keep-Alive")).IsFalse(); + } + public void Dispose() { _server?.Stop();