Преглед изворни кода

[System] Fill more WebException details when CONNECT fails. Fixes #19594

Marek Safar пре 9 година
родитељ
комит
81fb20737f

+ 5 - 2
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 ();

+ 9 - 1
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;