Skip to content

Commit ccf9fbf

Browse files
mconnewStephenBonikowsky
authored andcommitted
Add the Expect 100-Continue header when using a client certificate
1 parent 9aac44c commit ccf9fbf

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelFactory.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ protected ClientWebSocketFactory ClientWebSocketFactory
240240
}
241241
}
242242

243+
private bool AuthenticationSchemeMayRequireResend()
244+
{
245+
return AuthenticationScheme != AuthenticationSchemes.Anonymous;
246+
}
247+
243248
public override T GetProperty<T>()
244249
{
245250
if (typeof(T) == typeof(ISecurityCapabilities))
@@ -378,6 +383,13 @@ internal async Task<HttpClient> GetHttpClientAsync(EndpointAddress to, Uri via,
378383
if(!_keepAliveEnabled)
379384
httpClient.DefaultRequestHeaders.ConnectionClose = true;
380385

386+
#if !FEATURE_NETNATIVE // Expect continue not correctly supported on UAP
387+
if (IsExpectContinueHeaderRequired)
388+
{
389+
httpClient.DefaultRequestHeaders.ExpectContinue = true;
390+
}
391+
#endif
392+
381393
// We provide our own CancellationToken for each request. Setting HttpClient.Timeout to -1
382394
// prevents a call to CancellationToken.CancelAfter that HttpClient does internally which
383395
// causes TimerQueue contention at high load.
@@ -401,6 +413,8 @@ internal async Task<HttpClient> GetHttpClientAsync(EndpointAddress to, Uri via,
401413
return httpClient;
402414
}
403415

416+
internal virtual bool IsExpectContinueHeaderRequired => AuthenticationSchemeMayRequireResend();
417+
404418
internal virtual HttpClientHandler GetHttpClientHandler(EndpointAddress to, SecurityTokenContainer clientCertificateToken)
405419
{
406420
return new HttpClientHandler();
@@ -1296,13 +1310,6 @@ private bool PrepareMessageHeaders(Message message)
12961310
}
12971311
}
12981312

1299-
#if !FEATURE_NETNATIVE // Expect continue not correctly supported on UAP
1300-
if (AuthenticationSchemeMayRequireResend())
1301-
{
1302-
_httpRequestMessage.Headers.ExpectContinue = true;
1303-
}
1304-
#endif
1305-
13061313
if (action != null)
13071314
{
13081315
if (message.Version.Envelope == EnvelopeVersion.Soap11)
@@ -1351,7 +1358,7 @@ private void TryCompleteHttpRequest(HttpRequestMessage request)
13511358

13521359
private async Task SendPreauthenticationHeadRequestIfNeeded()
13531360
{
1354-
if (!AuthenticationSchemeMayRequireResend())
1361+
if (!_factory.AuthenticationSchemeMayRequireResend())
13551362
{
13561363
return;
13571364
}
@@ -1369,11 +1376,6 @@ private async Task SendPreauthenticationHeadRequestIfNeeded()
13691376
var cancelToken = await _timeoutHelper.GetCancellationTokenAsync();
13701377
await _httpClient.SendAsync(headHttpRequestMessage, cancelToken);
13711378
}
1372-
1373-
private bool AuthenticationSchemeMayRequireResend()
1374-
{
1375-
return _factory.AuthenticationScheme != AuthenticationSchemes.Anonymous;
1376-
}
13771379
}
13781380
}
13791381

src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpsChannelFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ internal override HttpClientHandler GetHttpClientHandler(EndpointAddress to, Sec
227227
return handler;
228228
}
229229

230+
internal override bool IsExpectContinueHeaderRequired => RequireClientCertificate || base.IsExpectContinueHeaderRequired;
231+
230232
private static void SetCertificate(HttpClientHandler handler, SecurityTokenContainer clientCertificateToken)
231233
{
232234
if (clientCertificateToken != null)

0 commit comments

Comments
 (0)