Esempio n. 1
0
        internal HTTPServerRequest(HTTPServerSession session)
        {
            _session = session;

            HTTPHeaderInputStream hs = new HTTPHeaderInputStream(session);
            Read(hs);
        }
Esempio n. 2
0
        internal HTTPServerResponse(HTTPServerSession session)
        {
            _session = session;

            _status = HTTPStatus.HTTP_OK;
            _reason = GetReasonForStatus(HTTPStatus.HTTP_OK);
        }
Esempio n. 3
0
        private void AcceptClient(IAsyncResult ar)
        {
            try
            {
                using (HTTPServerSession session = new HTTPServerSession(_socket.EndAccept(ar), _params))
                {
                    ManualResetEvent evt = ar.AsyncState as ManualResetEvent;
                    evt.Set();

                    while (session.HasMoreRequests)
                    {
                        try
                        {
                            HTTPServerResponse response = new HTTPServerResponse(session);
                            HTTPServerRequest  request  = new HTTPServerRequest(session);

                            response.Version   = request.Version;
                            response.KeepAlive = session.CanKeepAlive && request.KeepAlive && _params.KeepAlive;

                            try
                            {
                                IHTTPRequestHandler handler = _factory.CreateRequestHandler(request);
                                if (handler != null)
                                {
                                    if (request.ExpectsContinue)
                                    {
                                        response.SendContinue();
                                    }

                                    handler.HandleRequest(request, response);
                                    session.KeepAlive = response.KeepAlive && session.CanKeepAlive && _params.KeepAlive;
                                }
                                else
                                {
                                    SendErrorResponse(session, HTTPServerResponse.HTTPStatus.HTTP_NOT_IMPLEMENTED);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (!response.Sent)
                                {
                                    SendErrorResponse(session, HTTPServerResponse.HTTPStatus.HTTP_INTERNAL_SERVER_ERROR);
                                }

                                OnServerException(ex);
                                break;
                            }
                        }
                        catch (HTTPNoMessageException) { break; }
                        catch (HTTPMessageException)
                        {
                            SendErrorResponse(session, HTTPServerResponse.HTTPStatus.HTTP_BAD_REQUEST);
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            { }
        }
Esempio n. 4
0
        internal HTTPServerRequest(HTTPServerSession session)
        {
            _session = session;

            HTTPHeaderInputStream hs = new HTTPHeaderInputStream(session);

            Read(hs);
        }
Esempio n. 5
0
        private void SendErrorResponse(HTTPServerSession session, HTTPServerResponse.HTTPStatus status)
        {
            HTTPServerResponse response = new HTTPServerResponse(session);

            response.Version         = HTTPMessage.HTTP_1_1;
            response.StatusAndReason = status;
            response.KeepAlive       = false;
            response.Send();
            session.KeepAlive = false;
        }
Esempio n. 6
0
 public HTTPHeaderOutputStream(HTTPServerSession session)
 {
     _session = session;
 }
Esempio n. 7
0
 public HTTPOutputStream(HTTPServerSession session)
 {
     _session = session;
 }
 public HTTPFixedLengthOutputStream(HTTPServerSession session, long maxLength)
 {
     _session = session;
     _maxLength = maxLength;
 }
Esempio n. 9
0
 public HTTPFixedLengthInputStream(HTTPServerSession session, Int64 length)
 {
     _session = session;
     _length  = length;
     _read    = 0;
 }
Esempio n. 10
0
 public ChunkedStream(HTTPServerSession session)
     : base(session)
 {
 }
Esempio n. 11
0
 public HTTPHeaderInputStream(HTTPServerSession session)
 {
     _session = session;
 }
Esempio n. 12
0
 private void SendErrorResponse(HTTPServerSession session, HTTPServerResponse.HTTPStatus status)
 {
     HTTPServerResponse response = new HTTPServerResponse(session);
     response.Version = HTTPMessage.HTTP_1_1;
     response.StatusAndReason = status;
     response.KeepAlive = false;
     response.Send();
     session.KeepAlive = false;
 }
Esempio n. 13
0
        private void AcceptClient(IAsyncResult ar)
        {
            try
            {
                using (HTTPServerSession session = new HTTPServerSession(_socket.EndAccept(ar), _params))
                {
                    ManualResetEvent evt = ar.AsyncState as ManualResetEvent;
                    evt.Set();

                    while (session.HasMoreRequests)
                    {
                        try
                        {
                            HTTPServerResponse response = new HTTPServerResponse(session);
                            HTTPServerRequest request = new HTTPServerRequest(session);

                            response.Version = request.Version;
                            response.KeepAlive = session.CanKeepAlive && request.KeepAlive && _params.KeepAlive;

                            try
                            {
                                IHTTPRequestHandler handler = _factory.CreateRequestHandler(request);
                                if (handler != null)
                                {
                                    if (request.ExpectsContinue)
                                        response.SendContinue();

                                    handler.HandleRequest(request, response);
                                    if (handler.DetectInvalidPackageHeader()) break;

                                    session.KeepAlive = response.KeepAlive && session.CanKeepAlive && _params.KeepAlive;

                                    while (session.HasMoreRequests)
                                    {
                                        System.Threading.Thread.Sleep(1000);
                                    }

                                }
                                else
                                    SendErrorResponse(session, HTTPServerResponse.HTTPStatus.HTTP_NOT_IMPLEMENTED);
                            }
                            catch (Exception ex)
                            {
                                if (!response.Sent)
                                    SendErrorResponse(session, HTTPServerResponse.HTTPStatus.HTTP_INTERNAL_SERVER_ERROR);

                                OnServerException(ex);
                                break;
                            }
                        }
                        catch (HTTPNoMessageException) { break; }
                        catch (HTTPMessageException)
                        {
                            SendErrorResponse(session, HTTPServerResponse.HTTPStatus.HTTP_BAD_REQUEST);
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            { }
        }
 public HTTPFixedLengthOutputStream(HTTPServerSession session, long maxLength)
 {
     _session   = session;
     _maxLength = maxLength;
 }
Esempio n. 15
0
 public HTTPInputStream(HTTPServerSession session)
 {
     _session = session;
 }
 public HTTPFixedLengthInputStream(HTTPServerSession session, Int64 length)
 {
     _session = session;
     _length = length;
     _read = 0;
 }
Esempio n. 17
0
        internal HTTPServerResponse(HTTPServerSession session)
        {
            _session = session;

            _status = HTTPStatus.HTTP_OK;
            _reason = GetReasonForStatus(HTTPStatus.HTTP_OK);
        }