Skip to content

Commit f16dc0b

Browse files
committed
Merge branch 'develop@Sacrilege' into develop
Cherry picked from ThreeMammals#1521
2 parents fd4f73a + 8c0f6e0 commit f16dc0b

9 files changed

+63
-58
lines changed

src/Ocelot/Configuration/Creator/HttpHandlerOptionsCreator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public HttpHandlerOptions Create(FileHttpHandlerOptions options)
2222
int maxConnectionPerServer = (options.MaxConnectionsPerServer > 0) ? maxConnectionPerServer = options.MaxConnectionsPerServer : maxConnectionPerServer = int.MaxValue;
2323

2424
return new HttpHandlerOptions(options.AllowAutoRedirect,
25-
options.UseCookieContainer, useTracing, options.UseProxy, maxConnectionPerServer);
25+
options.UseCookieContainer, useTracing, options.UseProxy, maxConnectionPerServer, options.UseDefaultCredentials);
2626
}
2727
}
2828
}

src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public FileHttpHandlerOptions()
88
UseCookieContainer = false;
99
UseProxy = true;
1010
MaxConnectionsPerServer = int.MaxValue;
11+
UseDefaultCredentials = false;
1112
}
1213

1314
public bool AllowAutoRedirect { get; set; }
@@ -19,5 +20,7 @@ public FileHttpHandlerOptions()
1920
public bool UseProxy { get; set; }
2021

2122
public int MaxConnectionsPerServer { get; set; }
23+
24+
public bool UseDefaultCredentials { get; set; }
2225
}
2326
}

src/Ocelot/Configuration/HttpHandlerOptions.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
/// </summary>
77
public class HttpHandlerOptions
88
{
9-
public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool useTracing, bool useProxy, int maxConnectionsPerServer)
9+
public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool useTracing, bool useProxy, int maxConnectionsPerServer, bool useDefaultCredentials)
1010
{
1111
AllowAutoRedirect = allowAutoRedirect;
1212
UseCookieContainer = useCookieContainer;
1313
UseTracing = useTracing;
1414
UseProxy = useProxy;
1515
MaxConnectionsPerServer = maxConnectionsPerServer;
16+
UseDefaultCredentials = useDefaultCredentials;
1617
}
1718

18-
1919
/// <summary>
2020
/// Specify if auto redirect is enabled
2121
/// </summary>
@@ -44,6 +44,12 @@ public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool
4444
/// Specify the maximum of concurrent connection to a network endpoint
4545
/// </summary>
4646
/// <value>MaxConnectionsPerServer</value>
47-
public int MaxConnectionsPerServer { get; private set; }
47+
public int MaxConnectionsPerServer { get; private set; }
48+
49+
/// <summary>
50+
/// Specify is UseDefaultCredentials set on HttpClientHandler.
51+
/// </summary>
52+
/// <value>UseDefaultCredentials</value>
53+
public bool UseDefaultCredentials { get; private set; }
4854
}
4955
}

src/Ocelot/Configuration/HttpHandlerOptionsBuilder.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class HttpHandlerOptionsBuilder
77
private bool _useTracing;
88
private bool _useProxy;
99
private int _maxConnectionPerServer;
10+
private bool _useDefaultCredentials;
1011

1112
public HttpHandlerOptionsBuilder WithAllowAutoRedirect(bool input)
1213
{
@@ -31,16 +32,22 @@ public HttpHandlerOptionsBuilder WithUseProxy(bool useProxy)
3132
_useProxy = useProxy;
3233
return this;
3334
}
35+
3436
public HttpHandlerOptionsBuilder WithUseMaxConnectionPerServer(int maxConnectionPerServer)
3537
{
3638
_maxConnectionPerServer = maxConnectionPerServer;
3739
return this;
3840
}
3941

42+
public HttpHandlerOptionsBuilder WithUseDefaultCredentials(bool input)
43+
{
44+
_useDefaultCredentials = input;
45+
return this;
46+
}
4047

4148
public HttpHandlerOptions Build()
4249
{
43-
return new HttpHandlerOptions(_allowAutoRedirect, _useCookieContainer, _useTracing, _useProxy, _maxConnectionPerServer);
50+
return new HttpHandlerOptions(_allowAutoRedirect, _useCookieContainer, _useTracing, _useProxy, _maxConnectionPerServer, _useDefaultCredentials);
4451
}
4552
}
4653
}

src/Ocelot/Requester/HttpClientBuilder.cs

+9-20
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,23 @@ public IHttpClient Create(DownstreamRoute downstreamRoute)
6969

7070
private HttpClientHandler CreateHandler(DownstreamRoute downstreamRoute)
7171
{
72-
// Dont' create the CookieContainer if UseCookies is not set or the HttpClient will complain
73-
// under .Net Full Framework
74-
var useCookies = downstreamRoute.HttpHandlerOptions.UseCookieContainer;
75-
76-
return useCookies ? UseCookiesHandler(downstreamRoute) : UseNonCookiesHandler(downstreamRoute);
77-
}
78-
79-
private HttpClientHandler UseNonCookiesHandler(DownstreamRoute downstreamRoute)
80-
{
81-
return new HttpClientHandler
72+
var handler = new HttpClientHandler
8273
{
8374
AllowAutoRedirect = downstreamRoute.HttpHandlerOptions.AllowAutoRedirect,
8475
UseCookies = downstreamRoute.HttpHandlerOptions.UseCookieContainer,
8576
UseProxy = downstreamRoute.HttpHandlerOptions.UseProxy,
8677
MaxConnectionsPerServer = downstreamRoute.HttpHandlerOptions.MaxConnectionsPerServer,
78+
UseDefaultCredentials = downstreamRoute.HttpHandlerOptions.UseDefaultCredentials,
8779
};
88-
}
8980

90-
private HttpClientHandler UseCookiesHandler(DownstreamRoute downstreamRoute)
91-
{
92-
return new HttpClientHandler
81+
// Dont' create the CookieContainer if UseCookies is not set or the HttpClient will complain
82+
// under .Net Full Framework
83+
if (downstreamRoute.HttpHandlerOptions.UseCookieContainer)
9384
{
94-
AllowAutoRedirect = downstreamRoute.HttpHandlerOptions.AllowAutoRedirect,
95-
UseCookies = downstreamRoute.HttpHandlerOptions.UseCookieContainer,
96-
UseProxy = downstreamRoute.HttpHandlerOptions.UseProxy,
97-
MaxConnectionsPerServer = downstreamRoute.HttpHandlerOptions.MaxConnectionsPerServer,
98-
CookieContainer = new CookieContainer(),
99-
};
85+
handler.CookieContainer = new CookieContainer();
86+
}
87+
88+
return handler;
10089
}
10190

10291
public void Save()

test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void should_not_use_tracing_if_fake_tracer_registered()
4141
}
4242
};
4343

44-
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue);
44+
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, false);
4545

4646
this.Given(x => GivenTheFollowing(fileRoute))
4747
.When(x => WhenICreateHttpHandlerOptions())
@@ -60,7 +60,7 @@ public void should_use_tracing_if_real_tracer_registered()
6060
}
6161
};
6262

63-
var expectedOptions = new HttpHandlerOptions(false, false, true, true, int.MaxValue);
63+
var expectedOptions = new HttpHandlerOptions(false, false, true, true, int.MaxValue, false);
6464

6565
this.Given(x => GivenTheFollowing(fileRoute))
6666
.And(x => GivenARealTracer())
@@ -73,7 +73,7 @@ public void should_use_tracing_if_real_tracer_registered()
7373
public void should_create_options_with_useCookie_false_and_allowAutoRedirect_true_as_default()
7474
{
7575
var fileRoute = new FileRoute();
76-
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue);
76+
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, false);
7777

7878
this.Given(x => GivenTheFollowing(fileRoute))
7979
.When(x => WhenICreateHttpHandlerOptions())
@@ -94,7 +94,7 @@ public void should_create_options_with_specified_useCookie_and_allowAutoRedirect
9494
}
9595
};
9696

97-
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue);
97+
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, false);
9898

9999
this.Given(x => GivenTheFollowing(fileRoute))
100100
.When(x => WhenICreateHttpHandlerOptions())
@@ -110,7 +110,7 @@ public void should_create_options_with_useproxy_true_as_default()
110110
HttpHandlerOptions = new FileHttpHandlerOptions()
111111
};
112112

113-
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue);
113+
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, false);
114114

115115
this.Given(x => GivenTheFollowing(fileRoute))
116116
.When(x => WhenICreateHttpHandlerOptions())
@@ -129,7 +129,7 @@ public void should_create_options_with_specified_useproxy()
129129
}
130130
};
131131

132-
var expectedOptions = new HttpHandlerOptions(false, false, false, false, int.MaxValue);
132+
var expectedOptions = new HttpHandlerOptions(false, false, false, false, int.MaxValue, false);
133133

134134
this.Given(x => GivenTheFollowing(fileRoute))
135135
.When(x => WhenICreateHttpHandlerOptions())
@@ -148,7 +148,7 @@ public void should_create_options_with_specified_MaxConnectionsPerServer()
148148
}
149149
};
150150

151-
var expectedOptions = new HttpHandlerOptions(false, false, false, true, 10);
151+
var expectedOptions = new HttpHandlerOptions(false, false, false, true, 10, false);
152152

153153
this.Given(x => GivenTheFollowing(fileRoute))
154154
.When(x => WhenICreateHttpHandlerOptions())
@@ -167,7 +167,7 @@ public void should_create_options_fixing_specified_MaxConnectionsPerServer_range
167167
}
168168
};
169169

170-
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue);
170+
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, false);
171171

172172
this.Given(x => GivenTheFollowing(fileRoute))
173173
.When(x => WhenICreateHttpHandlerOptions())
@@ -186,7 +186,7 @@ public void should_create_options_fixing_specified_MaxConnectionsPerServer_range
186186
}
187187
};
188188

189-
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue);
189+
var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, false);
190190

191191
this.Given(x => GivenTheFollowing(fileRoute))
192192
.When(x => WhenICreateHttpHandlerOptions())

test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void should_follow_ordering_add_specifics()
5252

5353
var route = new DownstreamRouteBuilder()
5454
.WithQosOptions(qosOptions)
55-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
55+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue, false))
5656
.WithDelegatingHandlers(new List<string>
5757
{
5858
"FakeDelegatingHandler",
@@ -88,7 +88,7 @@ public void should_follow_ordering_order_specifics_and_globals()
8888

8989
var route = new DownstreamRouteBuilder()
9090
.WithQosOptions(qosOptions)
91-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
91+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue, false))
9292
.WithDelegatingHandlers(new List<string>
9393
{
9494
"FakeDelegatingHandlerTwo",
@@ -125,7 +125,7 @@ public void should_follow_ordering_order_specifics()
125125

126126
var route = new DownstreamRouteBuilder()
127127
.WithQosOptions(qosOptions)
128-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
128+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue, false))
129129
.WithDelegatingHandlers(new List<string>
130130
{
131131
"FakeDelegatingHandlerTwo",
@@ -161,7 +161,7 @@ public void should_follow_ordering_order_and_only_add_specifics_in_config()
161161

162162
var route = new DownstreamRouteBuilder()
163163
.WithQosOptions(qosOptions)
164-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
164+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue, false))
165165
.WithDelegatingHandlers(new List<string>
166166
{
167167
"FakeDelegatingHandler",
@@ -195,7 +195,7 @@ public void should_follow_ordering_dont_add_specifics()
195195

196196
var route = new DownstreamRouteBuilder()
197197
.WithQosOptions(qosOptions)
198-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
198+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue, false))
199199
.WithLoadBalancerKey("")
200200
.Build();
201201

@@ -221,7 +221,7 @@ public void should_apply_re_route_specific()
221221

222222
var route = new DownstreamRouteBuilder()
223223
.WithQosOptions(qosOptions)
224-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue))
224+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue, false))
225225
.WithDelegatingHandlers(new List<string>
226226
{
227227
"FakeDelegatingHandler",
@@ -249,7 +249,7 @@ public void should_all_from_all_routes_provider_and_qos()
249249

250250
var route = new DownstreamRouteBuilder()
251251
.WithQosOptions(qosOptions)
252-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue)).WithLoadBalancerKey("").Build();
252+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue, false)).WithLoadBalancerKey("").Build();
253253

254254
this.Given(x => GivenTheFollowingRequest(route))
255255
.And(x => GivenTheQosFactoryReturns(new FakeQoSHandler()))
@@ -269,7 +269,7 @@ public void should_return_provider_with_no_delegates()
269269

270270
var route = new DownstreamRouteBuilder()
271271
.WithQosOptions(qosOptions)
272-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue)).WithLoadBalancerKey("").Build();
272+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue, false)).WithLoadBalancerKey("").Build();
273273

274274
this.Given(x => GivenTheFollowingRequest(route))
275275
.And(x => GivenTheServiceProviderReturnsNothing())
@@ -289,7 +289,7 @@ public void should_return_provider_with_qos_delegate()
289289

290290
var route = new DownstreamRouteBuilder()
291291
.WithQosOptions(qosOptions)
292-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue)).WithLoadBalancerKey("").Build();
292+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue, false)).WithLoadBalancerKey("").Build();
293293

294294
this.Given(x => GivenTheFollowingRequest(route))
295295
.And(x => GivenTheQosFactoryReturns(new FakeQoSHandler()))
@@ -309,7 +309,7 @@ public void should_return_provider_with_qos_delegate_when_timeout_value_set()
309309

310310
var route = new DownstreamRouteBuilder()
311311
.WithQosOptions(qosOptions)
312-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue)).WithLoadBalancerKey("").Build();
312+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false, true, int.MaxValue, false)).WithLoadBalancerKey("").Build();
313313

314314
this.Given(x => GivenTheFollowingRequest(route))
315315
.And(x => GivenTheQosFactoryReturns(new FakeQoSHandler()))
@@ -331,7 +331,7 @@ public void should_log_error_and_return_no_qos_provider_delegate_when_qos_factor
331331

332332
var route = new DownstreamRouteBuilder()
333333
.WithQosOptions(qosOptions)
334-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
334+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue, false))
335335
.WithLoadBalancerKey("")
336336
.Build();
337337

@@ -361,7 +361,7 @@ public void should_log_error_and_return_no_qos_provider_delegate_when_qos_factor
361361

362362
var route = new DownstreamRouteBuilder()
363363
.WithQosOptions(qosOptions)
364-
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue))
364+
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true, true, int.MaxValue, false))
365365
.WithLoadBalancerKey("")
366366
.Build();
367367

0 commit comments

Comments
 (0)