Esempio n. 1
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)
            { }
        }
        internal HTTPServerResponse(HTTPServerSession session)
        {
            _session = session;

            _status = HTTPStatus.HTTP_OK;
            _reason = GetReasonForStatus(HTTPStatus.HTTP_OK);
        }
        internal HTTPServerRequest(HTTPServerSession session)
        {
            _session = session;

            HTTPHeaderInputStream hs = new HTTPHeaderInputStream(session);
            Read(hs);
        }
        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;
        }
 public HTTPHeaderInputStream(HTTPServerSession session)
 {
     _session = session;
 }
 public HTTPFixedLengthInputStream(HTTPServerSession session, Int64 length)
 {
     _session = session;
     _length  = length;
     _read    = 0;
 }
 public HTTPHeaderInputStream(HTTPServerSession session)
 {
     _session = session;
 }
Esempio n. 9
0
 public HTTPOutputStream(HTTPServerSession session)
 {
     _session = session;
 }
 public HTTPFixedLengthOutputStream(HTTPServerSession session, long maxLength)
 {
     _session = session;
     _maxLength = maxLength;
 }
Esempio n. 11
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. 12
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)
            { }
        }
        internal HTTPServerResponse(HTTPServerSession session)
        {
            _session = session;

            _status = HTTPStatus.HTTP_OK;
            _reason = GetReasonForStatus(HTTPStatus.HTTP_OK);
        }
 public HTTPFixedLengthInputStream(HTTPServerSession session, Int64 length)
 {
     _session = session;
     _length = length;
     _read = 0;
 }
 public HTTPFixedLengthOutputStream(HTTPServerSession session, long maxLength)
 {
     _session   = session;
     _maxLength = maxLength;
 }
 public HTTPOutputStream(HTTPServerSession session)
 {
     _session = session;
 }