Beispiel #1
0
        public void EndHeaders()
        {
            // Now that headers are over, all reading should be manual
            Autoread = false;

            // Prep the request
            DataAdapter = new Core.RequestDataAdapter(async delegate
            {
                await ReadAsync();
            });
            Request = new HTTP.Request(DataAdapter);
            Request.Headers = Headers;
            Request.Method = Method;
            Request.Protocol = Protocol;

            // Parse out the URI, which ends up being more annoying than it
            // should be.  Stay tuned...
            var uri = new Uri(Path, UriKind.RelativeOrAbsolute);

            // Set the path
            if (uri.IsAbsoluteUri)
                Request.Path = uri.AbsolutePath;
            else
                Request.Path = Path.Split('?')[0];

            // Set the host
            string temp;
            if (Headers.TryGetValue("host", out temp))
                Request.Host = temp;
            else if (uri.IsAbsoluteUri)
                Request.Host = uri.Host;
            else
                Request.Host = null;

            // Set the query
            if (uri.IsAbsoluteUri)
            {
                Request.Query = Util.FormUrlEncoding.Parse(uri.Query.Length > 0 ? uri.Query.Substring(1) : "");
            }
            else
            {
                var split = Path.Split(QuerySep, 2);
                Request.Query = Util.FormUrlEncoding.Parse(split.Length > 1 ? split[1] : "");
            }

            // Build the response
            bool keepAlive = Version == HTTP.Version.HTTP1_1;
            if (Headers.TryGetValue("connection", out temp))
            {
                temp = temp.ToLower();
                if (temp == "close")
                    keepAlive = false;
                else if (temp == "keep-alive")
                    keepAlive = true;
            }
            Response = new HTTP.Response(Version, this, keepAlive, delegate(bool forceDisconnect)
            {
                // Now that we're done, we should kill the client if
                // either the request expects it, or the response
                // requires it.
                if (forceDisconnect || !keepAlive)
                    Kill();
                else
                    Start();
            });

            // Since we've set up the request, it'll get scheduled at the END of the current
            // read call.  This prevents issues with overlapping reads, because reads are
            // guaranteed to have finished before we run any response logic.
        }
Beispiel #2
0
        public void Start()
        {
            // Set up the state
            Ready = true;
            Autoread = true;
            Request = null;
            Response = null;
            Version = HTTP.Version.HTTP1_0;
            Method = null;
            Path = null;
            Headers = null;
            DataAdapter = null;

            // If there's already a reader chugging away, simply setting
            // autoread will take care of it.  Otherwise, we need to restart
            // the reading.
            Read();
        }