internal HttpContext(HttpServerClient client, HttpServerRequest request)
 {
     Client   = client;
     Request  = request;
     Data     = new Hashtable();
     Response = new HttpServerResponse();
 }
Esempio n. 2
0
        async void AcceptCallback(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                StartAccept();

                HttpServerClient client;
                LinkedListNode <HttpServerClient> clientNode = clientsPool.Get();
                if (clientNode == null)
                {
                    client = new HttpServerClient(this, e.AcceptSocket);
                    client.KeepAliveCountdown = KeepAliveMax;
                    client.KeepAliveTimeout   = KeepAliveTimeout;
                    clientNode = new LinkedListNode <HttpServerClient>(client);
                }
                else
                {
                    client = clientNode.Value;
                    client.Reset(e.AcceptSocket);
                    client.KeepAliveCountdown = KeepAliveMax;
                    client.KeepAliveTimeout   = KeepAliveTimeout;
                }

                lock (instanceLock) {
                    clients.AddFirst(clientNode);
                }
                try {
                    await client.ProcessAsync();
                }
                catch (Exception exception) {
                    OnServerException(exception);
                }
                finally {
                    lock (instanceLock) {
                        clients.Remove(clientNode);
                    }
                    clientsPool.Release(clientNode);
                }
            }
        }
Esempio n. 3
0
        public HttpServerRequest(HttpServerClient client, string command, HttpHeaders headers, DateTime startTime, long startReadCounter)
        {
            this.client            = client;
            this.startTime         = startTime;
            this.startReadCounter  = startReadCounter;
            this.startWriteCounter = client.WriteCounter;

            HttpUtility.ParseCommand(command, out method, out fullPath, out path,
                                     out queryString, out queryStringArray, out protocol);
            AbsolutePath = Path;

            // handle HTTP headers
            Headers = headers;
            // handle cookies
            if (Headers.ContainsKey("cookie"))
            {
                Cookies = HttpUtility.ParseCookie(Headers["cookie"]);
            }
            else
            {
                Cookies = new Dictionary <string, string>();
            }
            // handle body stream
            if (Headers.ContainsKey("content-length"))
            {
                long contentLength = Convert.ToInt64(Headers["content-length"]);
                InputStream = new LengthLimitedStream(client.BufferContext, contentLength);
            }
            else if (Headers.ContainsKey("transfer-encoding") && (Headers["transfer-encoding"].ToLower() == "chunked"))
            {
                InputStream = new InputChunkedStream(client.BufferContext);
            }
            else
            {
                InputStream = new LengthLimitedStream(client.BufferContext, 0);
            }
        }