}\r
\r
private static readonly Regex HostAndPortRegex =\r
- new Regex("http://([^:/]+)(?::(\\d)+)?/", RegexOptions.Compiled);\r
+ new Regex("http://([^:/]+)(?::(\\d+))?/", RegexOptions.Compiled);\r
\r
private Socket ConnectServer()\r
{\r
port = int.Parse(m.Groups[2].Value);\r
_session.Request.RequestLine = _session.Request.RequestLine.Remove(m.Index, m.Length - 1);\r
}\r
- if (host == null)\r
- host = _session.Request.Host;\r
- if (host == null)\r
- throw new HttpProxyAbort("Can't find destinatio host");\r
+ if (host == null && !ParseAuthority(_session.Request.Host, ref host, ref port))\r
+ throw new HttpProxyAbort("Can't find destination host");\r
connect:\r
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);\r
socket.Connect(host, port);\r
return socket;\r
}\r
\r
+ private static readonly Regex AuthorityRegex = new Regex("([^:]+)(?::(\\d+))?");\r
+\r
+ private bool ParseAuthority(string authority, ref string host, ref int port)\r
+ {\r
+ if (string.IsNullOrEmpty(authority))\r
+ return false;\r
+ var m = AuthorityRegex.Match(authority);\r
+ if (!m.Success)\r
+ return false;\r
+ host = m.Groups[1].Value;\r
+ if (m.Groups[2].Success)\r
+ port = int.Parse(m.Groups[2].Value);\r
+ return true;\r
+ }\r
+\r
private void Close()\r
{\r
_serverStream?.Close();\r