public HttpClientResponse(string status, HttpHeaders headers, BufferContext bufferContext)
        {
            HttpUtility.ParseStatus(status, out protocol, out statusCode, out statusDescription);
            Headers = headers;
            if (Headers.ContainsKey("cookie"))
            {
                Cookies = HttpUtility.ParseCookie(Headers["cookie"]);
            }
            else
            {
                Cookies = new Dictionary <string, string>();
            }

            if (Headers.ContainsKey("content-length"))
            {
                long contentLength = Convert.ToInt64(Headers["content-length"]);
                InputStream = new LengthLimitedStream(bufferContext, contentLength);
            }
            else if (Headers.ContainsKey("transfer-encoding") && (Headers["transfer-encoding"].ToLower() == "chunked"))
            {
                InputStream = new InputChunkedStream(bufferContext);
            }
            else
            {
                InputStream = new LengthLimitedStream(bufferContext, 0);
            }
        }
Ejemplo n.º 2
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);
            }
        }