internal void FinishInitialization()
        {
            string item = this._headers["Host"];
            bool   flag = (item == null ? true : item.Length == 0);

            if (!((this._version > WebSocketSharp.Net.HttpVersion.Version10) & flag))
            {
                if (flag)
                {
                    item = this.UserHostAddress;
                }
                this._url = HttpUtility.CreateRequestUrl(this._uri, item, this.IsWebSocketRequest, this.IsSecureConnection);
                if (this._url != null)
                {
                    string str = this.Headers["Transfer-Encoding"];
                    if ((!(this._version > WebSocketSharp.Net.HttpVersion.Version10) || str == null ? false : str.Length > 0))
                    {
                        this._chunked = str.ToLower() == "chunked";
                        if (!this._chunked)
                        {
                            this._context.ErrorMessage = string.Empty;
                            this._context.ErrorStatus  = 501;
                            return;
                        }
                    }
                    if ((this._chunked ? false : !this._contentLengthSet))
                    {
                        string lower = this._method.ToLower();
                        if ((lower == "post" ? true : lower == "put"))
                        {
                            this._context.ErrorMessage = string.Empty;
                            this._context.ErrorStatus  = 411;
                            return;
                        }
                    }
                    string item1 = this.Headers["Expect"];
                    if ((item1 == null || item1.Length <= 0 ? false : item1.ToLower() == "100-continue"))
                    {
                        ResponseStream responseStream = this._context.Connection.GetResponseStream();
                        responseStream.InternalWrite(WebSocketSharp.Net.HttpListenerRequest._100continue, 0, (int)WebSocketSharp.Net.HttpListenerRequest._100continue.Length);
                    }
                }
                else
                {
                    this._context.ErrorMessage = "Invalid request url";
                }
            }
            else
            {
                this._context.ErrorMessage = "Invalid Host header";
            }
        }
        internal void FinishInitialization()
        {
            string host = UserHostName;

            if (version > HttpVersion.Version10 && (host == null || host.Length == 0))
            {
                context.ErrorMessage = "Invalid host name";
                return;
            }

            string path;
            Uri    raw_uri = null;

            if (raw_url.MaybeUri() && Uri.TryCreate(raw_url, UriKind.Absolute, out raw_uri))
            {
                path = raw_uri.PathAndQuery;
            }
            else
            {
                path = HttpUtility.UrlDecode(raw_url);
            }

            if ((host == null || host.Length == 0))
            {
                host = UserHostAddress;
            }

            if (raw_uri != null)
            {
                host = raw_uri.Host;
            }

            int colon = host.IndexOf(':');

            if (colon >= 0)
            {
                host = host.Substring(0, colon);
            }

            string base_uri = String.Format("{0}://{1}:{2}",
                                            (IsSecureConnection) ? "https" : "http",
                                            host,
                                            LocalEndPoint.Port);

            if (!Uri.TryCreate(base_uri + path, UriKind.Absolute, out url))
            {
                context.ErrorMessage = "Invalid url: " + base_uri + path;
                return;
            }

            CreateQueryString(url.Query);

            if (version >= HttpVersion.Version11)
            {
                string t_encoding = Headers ["Transfer-Encoding"];
                is_chunked = (t_encoding != null && String.Compare(t_encoding, "chunked", StringComparison.OrdinalIgnoreCase) == 0);
                // 'identity' is not valid!
                if (t_encoding != null && !is_chunked)
                {
                    context.Connection.SendError(null, 501);
                    return;
                }
            }

            if (!is_chunked && !cl_set)
            {
                if (String.Compare(method, "POST", StringComparison.OrdinalIgnoreCase) == 0 ||
                    String.Compare(method, "PUT", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    context.Connection.SendError(null, 411);
                    return;
                }
            }

            if (String.Compare(Headers ["Expect"], "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
            {
                ResponseStream output = context.Connection.GetResponseStream();
                output.InternalWrite(_100continue, 0, _100continue.Length);
            }
        }
Exemple #3
0
        internal void FinishInitialization()
        {
            string text = this._headers["Host"];
            bool   flag = text == null || text.Length == 0;

            if (this._version > HttpVersion.Version10 && flag)
            {
                this._context.ErrorMessage = "Invalid Host header";
                return;
            }
            if (flag)
            {
                text = this.UserHostAddress;
            }
            Uri    uri = this._rawUrl.ToUri();
            string text2;

            if (uri != null && uri.IsAbsoluteUri)
            {
                text  = uri.Host;
                text2 = uri.PathAndQuery;
            }
            else
            {
                text2 = HttpUtility.UrlDecode(this._rawUrl);
            }
            int num = text.IndexOf(':');

            if (num != -1)
            {
                text = text.Substring(0, num);
            }
            string text3 = (!this.IsWebSocketRequest) ? "http" : "ws";
            string text4 = string.Format("{0}://{1}:{2}{3}", new object[]
            {
                (!this.IsSecureConnection) ? text3 : (text3 + "s"),
                text,
                this.LocalEndPoint.Port,
                text2
            });

            if (!Uri.TryCreate(text4, UriKind.Absolute, out this._url))
            {
                this._context.ErrorMessage = "Invalid request url: " + text4;
                return;
            }
            this.createQueryString(this._url.Query);
            string text5 = this.Headers["Transfer-Encoding"];

            if (this._version >= HttpVersion.Version11 && text5 != null && text5.Length > 0)
            {
                this._chunked = (text5.ToLower() == "chunked");
                if (!this._chunked)
                {
                    this._context.ErrorMessage = string.Empty;
                    this._context.ErrorStatus  = 501;
                    return;
                }
            }
            if (!this._chunked && !this._contentLengthWasSet)
            {
                string a = this._method.ToLower();
                if (a == "post" || a == "put")
                {
                    this._context.ErrorMessage = string.Empty;
                    this._context.ErrorStatus  = 411;
                    return;
                }
            }
            string text6 = this.Headers["Expect"];

            if (text6 != null && text6.Length > 0 && text6.ToLower() == "100-continue")
            {
                ResponseStream responseStream = this._context.Connection.GetResponseStream();
                responseStream.InternalWrite(HttpListenerRequest._100continue, 0, HttpListenerRequest._100continue.Length);
            }
        }