From f149851e3bf13859cf50319ec8990935f2e0076a Mon Sep 17 00:00:00 2001 From: noisyfox Date: Fri, 16 Dec 2016 12:19:09 +1100 Subject: [PATCH] Revert "Better host parse" This reverts commit d1e8f387673cafc4f54d925b4d8f6d36b651a667. --- .../Controller/Service/Http2Socks5.cs | 47 +++++++++++----------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/Http2Socks5.cs b/shadowsocks-csharp/Controller/Service/Http2Socks5.cs index 6ec9f6ab..094ab104 100644 --- a/shadowsocks-csharp/Controller/Service/Http2Socks5.cs +++ b/shadowsocks-csharp/Controller/Service/Http2Socks5.cs @@ -378,25 +378,6 @@ namespace Shadowsocks.Controller.Service private int _targetPort; private readonly Queue _headers = new Queue(); - private bool ParseHost(string host) - { - var locs = host.Split(':'); - _targetHost = locs[0]; - if (locs.Length > 1) - { - if (!int.TryParse(locs[1], out _targetPort)) - { - return false; - } - } - else - { - _targetPort = 80; - } - - return true; - } - private bool OnLineRead(string line, object state) { if (_closed) @@ -422,9 +403,19 @@ namespace Shadowsocks.Controller.Service { _isConnect = true; - if (!ParseHost(m.Groups[2].Value)) + var location = m.Groups[2].Value; + var locs = location.Split(':'); + _targetHost = locs[0]; + if (locs.Length > 1) { - throw new Exception("Bad http header: " + line); + if (!int.TryParse(locs[1], out _targetPort)) + { + throw new Exception("Bad http header: " + line); + } + } + else + { + _targetPort = 80; } } } @@ -440,9 +431,19 @@ namespace Shadowsocks.Controller.Service { if (line.StartsWith("Host: ")) { - if (!ParseHost(line.Substring(6).Trim())) + var location = line.Substring(6).Trim(); + var locs = location.Split(':'); + _targetHost = locs[0]; + if (locs.Length > 1) + { + if (!int.TryParse(locs[1], out _targetPort)) + { + throw new Exception("Bad http header: " + line); + } + } + else { - throw new Exception("Bad http header: " + line); + _targetPort = 80; } } }