From 81fb20737f810def6dde88d87a1b2f23cdb736c3 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Sat, 1 Oct 2016 00:10:03 +0200 Subject: [PATCH] [System] Fill more WebException details when CONNECT fails. Fixes #19594 --- mcs/class/System/System.Net/HttpWebRequest.cs | 7 +++++-- mcs/class/System/System.Net/WebConnection.cs | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mcs/class/System/System.Net/HttpWebRequest.cs b/mcs/class/System/System.Net/HttpWebRequest.cs index 1d48dfe0b87..a57c579250e 100644 --- a/mcs/class/System/System.Net/HttpWebRequest.cs +++ b/mcs/class/System/System.Net/HttpWebRequest.cs @@ -1320,8 +1320,11 @@ namespace System.Net msg = "Error: " + status; wex = new WebException (msg, status); } else { - msg = String.Format ("Error: {0} ({1})", status, exc.Message); - wex = new WebException (msg, status, WebExceptionInternalStatus.RequestFatal, exc); + wex = exc as WebException; + if (wex == null) { + msg = String.Format ("Error: {0} ({1})", status, exc.Message); + wex = new WebException (msg, status, WebExceptionInternalStatus.RequestFatal, exc); + } } r.SetCompleted (false, wex); r.DoCallback (); diff --git a/mcs/class/System/System.Net/WebConnection.cs b/mcs/class/System/System.Net/WebConnection.cs index c1bd5271adf..afc452f7cc6 100644 --- a/mcs/class/System/System.Net/WebConnection.cs +++ b/mcs/class/System/System.Net/WebConnection.cs @@ -293,6 +293,7 @@ namespace System.Net Data.StatusCode = status; Data.Challenge = result.GetValues ("Proxy-Authentic"); + Data.Headers = result; return false; } else if (status != 200) { string msg = String.Format ("The remote server returned a {0} status code.", status); @@ -368,6 +369,9 @@ namespace System.Net } status = (int)UInt32.Parse (parts [1]); + if (parts.Length >= 3) + Data.StatusDescription = String.Join (" ", parts, 2, parts.Length - 2); + gotStatus = true; } } @@ -738,7 +742,11 @@ namespace System.Net Exception cnc_exc = connect_exception; if (cnc_exc == null && (Data.StatusCode == 401 || Data.StatusCode == 407)) { st = WebExceptionStatus.ProtocolError; - cnc_exc = new WebException (Data.StatusCode == 407 ? "(407) Proxy Authentication Required" : "(401) Unauthorized" , st); + if (Data.Headers == null) + Data.Headers = new WebHeaderCollection (); + + var webResponse = new HttpWebResponse (sPoint.Address, "CONNECT", Data, null); + cnc_exc = new WebException (Data.StatusCode == 407 ? "(407) Proxy Authentication Required" : "(401) Unauthorized", null, st, webResponse); } connect_exception = null; -- 2.25.1