Parcourir la source

[Http]: Read version from "HTTP CONNECT" response.

When using "HTTP CONNECT" to create a tunnel to a proxy server,
check the proxy server's response for the HTTP Version and close
the connection if it's HTTP/1.0.
Martin Baulig il y a 11 ans
Parent
commit
e6ce33bc7d

+ 14 - 3
mcs/class/System/System.Net/WebConnection.cs

@@ -398,13 +398,22 @@ namespace System.Net
 						continue;
 					}
 
-					int spaceidx = str.IndexOf (' ');
-					if (spaceidx == -1) {
+					string[] parts = str.Split (' ');
+					if (parts.Length < 2) {
 						HandleError (WebExceptionStatus.ServerProtocolViolation, null, "ReadHeaders2");
 						return null;
 					}
 
-					status = (int) UInt32.Parse (str.Substring (spaceidx + 1, 3));
+					if (String.Compare (parts [0], "HTTP/1.1", true) == 0)
+						Data.ProxyVersion = HttpVersion.Version11;
+					else if (String.Compare (parts [0], "HTTP/1.0", true) == 0)
+						Data.ProxyVersion = HttpVersion.Version10;
+					else {
+						HandleError (WebExceptionStatus.ServerProtocolViolation, null, "ReadHeaders2");
+						return null;
+					}
+
+					status = (int)UInt32.Parse (parts [1]);
 					gotStatus = true;
 				}
 			}
@@ -840,6 +849,8 @@ namespace System.Net
 				string header = (sPoint.UsesProxy) ? "Proxy-Connection" : "Connection";
 				string cncHeader = (Data.Headers != null) ? Data.Headers [header] : null;
 				bool keepAlive = (Data.Version == HttpVersion.Version11 && this.keepAlive);
+				if (Data.ProxyVersion != null && Data.ProxyVersion != HttpVersion.Version11)
+					keepAlive = false;
 				if (cncHeader != null) {
 					cncHeader = cncHeader.ToLower ();
 					keepAlive = (this.keepAlive && cncHeader.IndexOf ("keep-alive", StringComparison.Ordinal) != -1);

+ 1 - 0
mcs/class/System/System.Net/WebConnectionData.cs

@@ -39,6 +39,7 @@ namespace System.Net
 		public string StatusDescription;
 		public WebHeaderCollection Headers;
 		public Version Version;
+		public Version ProxyVersion;
 		public Stream stream;
 		public string[] Challenge;
 		ReadState _readState;