[System] Fill more WebException details when CONNECT fails. Fixes #19594
authorMarek Safar <marek.safar@gmail.com>
Fri, 30 Sep 2016 22:10:03 +0000 (00:10 +0200)
committerMarek Safar <marek.safar@gmail.com>
Fri, 30 Sep 2016 22:11:23 +0000 (00:11 +0200)
mcs/class/System/System.Net/HttpWebRequest.cs
mcs/class/System/System.Net/WebConnection.cs

index 1d48dfe0b87af4f3729fa0b14caf4dc9558ab373..a57c579250ed33e6f27cb11ad04469840f3a06b3 100644 (file)
@@ -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 ();
index c1bd5271adf78ba7dbb25aac7638d8cb7a676378..afc452f7cc62474d137383f7941f292974007762 100644 (file)
@@ -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;