diff options
author | Martin Baulig <martin.baulig@xamarin.com> | 2014-04-18 00:27:19 +0400 |
---|---|---|
committer | Martin Baulig <martin.baulig@xamarin.com> | 2014-04-18 00:39:43 +0400 |
commit | 585aa54a23cd768c5928f2d6d6e88cfe88ce449f (patch) | |
tree | 8fd754062138ef6b6912d897d0822b0633969bb5 | |
parent | 3f61b88aa730163aeb24a1f9db9fed6e919d39d9 (diff) |
[Http]: Correctly handle request bodies when resending with authentication.
My previous changes modified the way how we're handing the request body when
resending a request due to a 30x redirection.
Authentication is a "special" form of redirection because we sometimes need
to resend a request with additional authentication headers. Unfortunately,
I forgot this, causing a regression which is now fixed.
This has been reported as bugs #19119 and #19068.
-rw-r--r-- | mcs/class/System/System.Net/HttpWebRequest.cs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/mcs/class/System/System.Net/HttpWebRequest.cs b/mcs/class/System/System.Net/HttpWebRequest.cs index 0c4be7268f1..cfee2391478 100644 --- a/mcs/class/System/System.Net/HttpWebRequest.cs +++ b/mcs/class/System/System.Net/HttpWebRequest.cs @@ -1156,12 +1156,6 @@ namespace System.Net throw e; contentLength = -1; - //bodyBufferLength = 0; - //bodyBuffer = null; - if (sendChunked) { - sendChunked = false; - webHeaders.RemoveInternal ("Transfer-Encoding"); - } uriString = webResponse.Headers ["Location"]; if (uriString == null) @@ -1191,7 +1185,10 @@ namespace System.Net } else if (contentLength != -1) { if (auth_state.NtlmAuthState == NtlmAuthState.Challenge || proxy_auth_state.NtlmAuthState == NtlmAuthState.Challenge) { // We don't send any body with the NTLM Challenge request. - webHeaders.SetInternal ("Content-Length", "0"); + if (haveContentLength || gotRequestStream || contentLength > 0) + webHeaders.SetInternal ("Content-Length", "0"); + else + webHeaders.RemoveInternal ("Content-Length"); } else { if (contentLength > 0) continue100 = true; @@ -1534,6 +1531,11 @@ namespace System.Net r.SetCompleted (false, webResponse); r.DoCallback (); } else { + if (sendChunked) { + sendChunked = false; + webHeaders.RemoveInternal ("Transfer-Encoding"); + } + if (webResponse != null) { if (HandleNtlmAuth (r)) return; @@ -1668,11 +1670,7 @@ namespace System.Net if (!usedPreAuth && CheckAuthorization (webResponse, code)) { // Keep the written body, so it can be rewritten in the retry if (InternalAllowBuffering) { - // NTLM: This is to avoid sending data in the 'challenge' request - // We save it in the first request (first 401), don't send anything - // in the challenge request and send it in the response request along - // with the buffers kept form the first request. - if (auth_state.NtlmAuthState == NtlmAuthState.Challenge || proxy_auth_state.NtlmAuthState == NtlmAuthState.Challenge) { + if (writeStream.WriteBufferLength > 0) { bodyBuffer = writeStream.WriteBuffer; bodyBufferLength = writeStream.WriteBufferLength; } |