Exemplo n.º 1
0
        private void ParseCodeAndText(string line)
        {
            int    begin = 0;
            int    end   = 0;
            string val   = null;

            if (line.IndexOf("HTTP") == -1)
            {
                throw new ProxyException(String.Format("No HTTP response received from proxy destination.  Server response: {0}.", line));
            }

            begin = line.IndexOf(" ") + 1;
            end   = line.IndexOf(" ", begin);

            val = line.Substring(begin, end - begin);
            Int32 code = 0;

            if (!Int32.TryParse(val, out code))
            {
                throw new ProxyException(String.Format("An invalid response code was received from proxy destination.  Server response: {0}.", line));
            }

            _respCode = (HttpResponseCodes)code;
            _respText = line.Substring(end + 1).Trim();
        }
Exemplo n.º 2
0
        private void HandleProxyCommandError(Socket socket, string host, int port, HttpResponseCodes code, string text)
        {
            string msg;

            switch (code)
            {
                case HttpResponseCodes.None:
                    msg = String.Format(CultureInfo.InvariantCulture, "Proxy destination {0} on port {1} failed to return a recognized HTTP response code.  Server response: {2}", ((System.Net.IPEndPoint)socket.RemoteEndPoint).Address.ToString(), ((System.Net.IPEndPoint)socket.RemoteEndPoint).Port.ToString(), text);
                    break;

                case HttpResponseCodes.BadGateway:
                    // HTTP/1.1 502 Proxy Error (The specified Secure Sockets Layer (SSL) port is not allowed. ISA Server is not configured to allow SSL requests from this port. Most Web browsers use port 443 for SSL requests.)
                    msg = String.Format(CultureInfo.InvariantCulture, "Proxy destination {0} on port {1} responded with a 502 code - Bad Gateway.  If you are connecting to a Microsoft ISA destination please refer to knowledge based article Q283284 for more information.  Server response: {2}", ((System.Net.IPEndPoint)socket.RemoteEndPoint).Address.ToString(), ((System.Net.IPEndPoint)socket.RemoteEndPoint).Port.ToString(), text);
                    break;

                default:
                    msg = String.Format(CultureInfo.InvariantCulture, "Proxy destination {0} on port {1} responded with a {2} code - {3}", ((System.Net.IPEndPoint)socket.RemoteEndPoint).Address.ToString(), ((System.Net.IPEndPoint)socket.RemoteEndPoint).Port.ToString(), ((int)code).ToString(CultureInfo.InvariantCulture), text);
                    break;
            }

            // throw a new application exception
            throw new ProxyClientException(msg);
        }
Exemplo n.º 3
0
        void ParseCodeAndText(string line)
        {
            if (line.IndexOf("HTTP") == -1)
                throw new ProxyException(string.Format("No HTTP response received from proxy destination.  Server response: {0}.", line));

            var begin = line.IndexOf(" ") + 1;
            var end = line.IndexOf(" ", begin);

            var val = line.Substring(begin, end - begin);

            int code;
            if (!int.TryParse(val, out code))
                throw new ProxyException(string.Format("An invalid response code was received from proxy destination.  Server response: {0}.", line));

            _respCode = (HttpResponseCodes)code;
            _respText = line.Substring(end + 1).Trim();
        }
Exemplo n.º 4
0
        private void ParseCodeAndText(string line)
        {
            int begin = 0;
            int end = 0;
            string val = null;

            if (line.IndexOf("HTTP") == -1)
            {
                throw new ProxyClientException(String.Format("No HTTP response received from proxy destination.  Server response: {0}.", line));
            }

            begin = line.IndexOf(" ") + 1;
            end = line.IndexOf(" ", begin);

            val = line.Substring(begin, end - begin);
            Int32 code = 0;

            if (!Int32.TryParse(val, out code))
            {
                throw new ProxyClientException(String.Format("An invalid response code was received from proxy destination.  Server response: {0}.", line));
            }

            _respCode = (HttpResponseCodes)code;
            _respText = line.Substring(end + 1).Trim();
        }