Ejemplo n.º 1
0
        private void ParseContent()
        {
            _stream.Position = 0;

            string content;

            using (var reader = new StreamReader(_stream, Encoding.ASCII))
            {
                content = reader.ReadToEnd();
            }

            HttpUtil.UrlDecodeTo(content, Client.PostParameters);
        }
Ejemplo n.º 2
0
        private void ParsePath(HttpClient client)
        {
            RawUrl = client.Request;

            string[] parts = client.Request.Split(new[] { '?' }, 2);

            Path = parts[0];

            QueryString = new NameValueCollection();
            if (parts.Length == 2)
            {
                HttpUtil.UrlDecodeTo(parts[1], QueryString);
            }

            string host;
            string port;
            string hostHeader;

            if (client.Headers.TryGetValue("Host", out hostHeader))
            {
                parts = hostHeader.Split(new[] { ':' }, 2);

                host = parts[0];

                if (parts.Length == 2)
                {
                    port = parts[1];
                }
                else
                {
                    port = null;
                }
            }
            else
            {
                var endPoint = client.Server.EndPoint;

                host = endPoint.Address.ToString();

                if (endPoint.Port == 80)
                {
                    port = null;
                }
                else
                {
                    port = endPoint.Port.ToString(CultureInfo.InvariantCulture);
                }
            }

            var sb = new StringBuilder();

            sb.Append("http://");
            sb.Append(host);

            if (port != null)
            {
                sb.Append(':');
                sb.Append(port);
            }

            sb.Append(client.Request);

            Url = new Uri(sb.ToString());
        }