Ejemplo n.º 1
0
        void ProcessResponse(HttpConnection conn, IHttpRequest req, HttpResponseHeader header, object result, ref bool keepAlive, ref bool header_sent)
        {
            byte[] rawBody = null;
            if (result is Stream)
            {
                try {
                    header[HttpHeaderNames.ContentLength] = (result as Stream).Length.ToString();
                } catch { }
            }
            else
            {
                rawBody = ResponseBodyToBytes(result);
                header[HttpHeaderNames.ContentLength] = rawBody.Length.ToString();
            }

            if (keepAlive && header.GetNotNullValue(HttpHeaderNames.ContentLength).Length == 0 && !header.GetNotNullValue(HttpHeaderNames.TransferEncoding).ToLower().Equals("chunked"))
            {
                keepAlive = false;
                header[HttpHeaderNames.Connection] = "close";
            }
            else if (header[HttpHeaderNames.Connection] == "close")
            {
                keepAlive = false;
            }

            byte[] raw = header.CreateResponseHeaderBytes();
            header_sent = true;
            conn.Send(raw);
            if (req.HttpMethod == HttpMethod.HEAD)
            {
                return;
            }
            if (rawBody != null)
            {
                conn.Send(rawBody);
            }
            else
            {
                // TODO: impelements to send stream data
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        void StartApplication(IHttpRequest req, HttpConnection conn, Encoding encoding, out bool keepAlive, out CometInfo cometInfo)
        {
            bool header_sent          = false;
            HttpResponseHeader header = new HttpResponseHeader(req);

            keepAlive = header.GetNotNullValue(HttpHeaderNames.Connection).ToLower().Equals("keep-alive");
            cometInfo = null;

            try {
                object result = _app.Process(this, req, header);
                cometInfo = result as CometInfo;
                if (cometInfo != null)
                {
                    return;
                }
                ProcessResponse(conn, req, header, result, ref keepAlive, ref header_sent);
            } catch (Exception e) {
                ProcessInternalError(conn, req, header, header_sent, e, ref keepAlive);
            }
        }