diff --git a/src/Ocelot/Configuration/HttpHandlerOptions.cs b/src/Ocelot/Configuration/HttpHandlerOptions.cs index 4b6cfabea4..16a7b0bc3e 100644 --- a/src/Ocelot/Configuration/HttpHandlerOptions.cs +++ b/src/Ocelot/Configuration/HttpHandlerOptions.cs @@ -65,6 +65,6 @@ public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool /// if the default credentials are used; otherwise . The default value is . /// The property value is assignable to the one. /// - public bool UseDefaultCredentials { get; private set; } + public bool UseDefaultCredentials { get; } } } diff --git a/src/Ocelot/Requester/MessageInvokerPool.cs b/src/Ocelot/Requester/MessageInvokerPool.cs index 130b4bccbf..7303657a46 100644 --- a/src/Ocelot/Requester/MessageInvokerPool.cs +++ b/src/Ocelot/Requester/MessageInvokerPool.cs @@ -77,6 +77,7 @@ private HttpMessageHandler CreateHandler(DownstreamRoute downstreamRoute) UseProxy = downstreamRoute.HttpHandlerOptions.UseProxy, MaxConnectionsPerServer = downstreamRoute.HttpHandlerOptions.MaxConnectionsPerServer, PooledConnectionLifetime = downstreamRoute.HttpHandlerOptions.PooledConnectionLifeTime, + Credentials = downstreamRoute.HttpHandlerOptions.UseDefaultCredentials ? CredentialCache.DefaultCredentials : null, }; if (downstreamRoute.HttpHandlerOptions.UseCookieContainer) diff --git a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs index e762353277..eb64eed151 100644 --- a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs @@ -185,6 +185,41 @@ public void should_create_options_fixing_specified_MaxConnectionsPerServer_range .Then(x => ThenTheFollowingOptionsReturned(expectedOptions)) .BDDfy(); } + + [Fact] + public void Should_create_options_with_useDefaultCredentials_false_as_default() + { + var fileRoute = new FileRoute + { + HttpHandlerOptions = new FileHttpHandlerOptions(), + }; + + var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, DefaultPooledConnectionLifeTime, false); + + this.Given(x => GivenTheFollowing(fileRoute)) + .When(x => WhenICreateHttpHandlerOptions()) + .Then(x => ThenTheFollowingOptionsReturned(expectedOptions)) + .BDDfy(); + } + + [Fact] + public void Should_create_options_with_useDefaultCredentials_true_if_set() + { + var fileRoute = new FileRoute + { + HttpHandlerOptions = new FileHttpHandlerOptions + { + UseDefaultCredentials = true, + }, + }; + + var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, DefaultPooledConnectionLifeTime, true); + + this.Given(x => GivenTheFollowing(fileRoute)) + .When(x => WhenICreateHttpHandlerOptions()) + .Then(x => ThenTheFollowingOptionsReturned(expectedOptions)) + .BDDfy(); + } private void GivenTheFollowing(FileRoute fileRoute) { @@ -203,7 +238,8 @@ private void ThenTheFollowingOptionsReturned(HttpHandlerOptions expected) _httpHandlerOptions.UseCookieContainer.ShouldBe(expected.UseCookieContainer); _httpHandlerOptions.UseTracing.ShouldBe(expected.UseTracing); _httpHandlerOptions.UseProxy.ShouldBe(expected.UseProxy); - _httpHandlerOptions.MaxConnectionsPerServer.ShouldBe(expected.MaxConnectionsPerServer); + _httpHandlerOptions.MaxConnectionsPerServer.ShouldBe(expected.MaxConnectionsPerServer); + _httpHandlerOptions.UseDefaultCredentials.ShouldBe(expected.UseDefaultCredentials); } private void GivenARealTracer()