コード例 #1
0
ファイル: HttpClientContext.cs プロジェクト: kow/Aurora-Sim
        private void OnRequestCompleted(object source, EventArgs args)
        {
            try
            {
                _currentRequest.AddHeader("remote_addr", RemoteAddress);
                _currentRequest.AddHeader("remote_port", RemotePort);

                // load cookies if they exist
                RequestCookies cookies = _currentRequest.Headers["cookie"] != null
                    ? new RequestCookies(_currentRequest.Headers["cookie"])
                    : new RequestCookies(String.Empty);
                _currentRequest.SetCookies(cookies);
                if (_currentRequest.Body != null && _currentRequest.Body.CanRead)
                {
                    _currentRequest.Body.Seek(0, SeekOrigin.Begin);
                    RequestReceived(this, new RequestEventArgs(_currentRequest));
                }
                else
                {
                    LogWriter.Write(this, LogPrio.Warning, "Failed to complete receive, request was null or could not be read.");
                    Disconnect(SocketError.SocketError);
                }
                _currentRequest.Clear();
            }
            catch (Exception err)
            {
                LogWriter.Write(this, LogPrio.Warning, "Failed to complete receive : Exception: " + err.ToString());
                Disconnect(SocketError.NoRecovery);
            }
        }
コード例 #2
0
        private void OnRequestCompleted(object source, EventArgs args)
        {
            _currentRequest.AddHeader("remote_addr", RemoteAddress);
            _currentRequest.AddHeader("remote_port", RemotePort);

            // load cookies if they exist
            RequestCookies cookies = _currentRequest.Headers["cookie"] != null
                ? new RequestCookies(_currentRequest.Headers["cookie"])
                : new RequestCookies(String.Empty);

            _currentRequest.SetCookies(cookies);

            _currentRequest.Body.Seek(0, SeekOrigin.Begin);
            RequestReceived(this, new RequestEventArgs(_currentRequest));

            FullRequestReceived = true;

            if (_currentRequest.Connection == ConnectionType.Close)
            {
                _sock = null;
            }
            else
            {
                TriggerKeepalive = true;
            }

            if (!StreamPassedOff)
            {
                _currentRequest.Clear();
            }
        }
コード例 #3
0
        private void OnRequestCompleted(object source, EventArgs args)
        {
            _currentRequest.AddHeader("remote_addr", RemoteAddress);
            _currentRequest.AddHeader("remote_port", RemotePort);

            // load cookies if they exist
            RequestCookies cookies = _currentRequest.Headers["cookie"] != null
                ? new RequestCookies(_currentRequest.Headers["cookie"])
                : new RequestCookies(String.Empty);

            _currentRequest.SetCookies(cookies);

            _currentRequest.Body.Seek(0, SeekOrigin.Begin);
            RequestReceived(this, new RequestEventArgs(_currentRequest));
            _currentRequest.Clear();
        }
コード例 #4
0
        private void OnRequestCompleted(object source, EventArgs args)
        {
            TriggerKeepalive   = false;
            MonitorKeepaliveMS = 0;

            // load cookies if they exist
            RequestCookies cookies = m_currentRequest.Headers["cookie"] != null
                ? new RequestCookies(m_currentRequest.Headers["cookie"])
                : new RequestCookies(String.Empty);

            m_currentRequest.SetCookies(cookies);

            m_currentRequest.Body.Seek(0, SeekOrigin.Begin);

            FullRequestReceived = true;

            int nreqs;

            lock (requestsInServiceIDs)
            {
                nreqs = requestsInServiceIDs.Count;
                requestsInServiceIDs.Add(m_currentRequest.ID);
                if (m_maxRequests > 0)
                {
                    m_maxRequests--;
                }
            }

            // for now pipeline requests need to be serialized by opensim
            RequestReceived(this, new RequestEventArgs(m_currentRequest));

            m_currentRequest = new HttpRequest(this);

            int nreqsnow;

            lock (requestsInServiceIDs)
            {
                nreqsnow = requestsInServiceIDs.Count;
            }
            if (nreqs != nreqsnow)
            {
                // request was not done by us
            }
        }
コード例 #5
0
        /// <summary>
        /// Clear everything in the request
        /// </summary>
        public void Clear()
        {
            _body.Dispose();
            _body          = new MemoryStream();
            _contentLength = 0;
            _method        = string.Empty;
            _uri           = null;
            _queryString   = HttpInput.Empty;
            _bodyBytesLeft = 0;
            _headers.Clear();
            _connection = ConnectionType.Close;
            _param.SetForm(HttpInput.Empty);
            _param.SetQueryString(HttpInput.Empty);
            _form.Clear();

            AcceptTypes = null;
            Cookies     = null;
            IsAjax      = false;
            UriParts    = null;
        }
コード例 #6
0
 ///<summary>
 /// Cookies
 ///</summary>
 ///<param name="cookies">the cookies</param>
 public void SetCookies(RequestCookies cookies)
 {
     Cookies = cookies;
 }
コード例 #7
0
ファイル: HttpServer.cs プロジェクト: RainsSoft/HttpWebServer
        private void ProcessRequest(IHttpClientContext context, IHttpRequest request)
        {
            IHttpResponse response = request.CreateResponse(context);

            try
            {
                foreach (IRule rule in _rules)
                {
                    if (!rule.Process(request, response))
                    {
                        continue;
                    }
                    response.Send();
                    return;
                }

                // load cookies if the exist.
                RequestCookies cookies = request.Headers["cookie"] != null
                                                                                         ? new RequestCookies(request.Headers["cookie"])
                                                                                         : new RequestCookies(string.Empty);

                request.SetCookies(cookies);

                IHttpSession session;
                if (cookies[_sessionCookieName] != null)
                {
                    string sessionCookie = cookies[_sessionCookieName].Value;

                    // there's a bug somewhere which f***s up headers which can render the session cookie useless.
                    // therefore let's consider the session cookie as not set if that have happened.
                    if (sessionCookie.Length > 40)
                    {
                        LogWriter.Write(this, LogPrio.Error, "Session cookie is invalid: " + sessionCookie);
                        cookies.Remove(_sessionCookieName);
                        _sessionStore.Remove(sessionCookie);                         // free the session cookie (and thus generating a new one).
                        session = _sessionStore.Create();
                    }
                    else
                    {
                        session = _sessionStore.Load(sessionCookie) ??
                                  _sessionStore.Create(sessionCookie);
                    }
                }
                else
                {
                    session = _sessionStore.Create();
                }

                HandleRequest(context, request, response, session);
            }
            catch (Exception err)
            {
                if (_exceptionHandler == null)
#if DEBUG
                { throw; }
#else
                {
                    WriteLog(LogPrio.Fatal, err.Message);
                    return;
                }
#endif
                _exceptionHandler(this, err);

                Exception e = err;
                while (e != null)
                {
                    if (e is SocketException)
                    {
                        return;
                    }

                    e = e.InnerException;
                }

                try
                {
#if DEBUG
                    context.Respond("HTTP/1.0", HttpStatusCode.InternalServerError, "Internal server error", err.ToString(), "text/plain");
#else
                    context.Respond("HTTP/1.0", HttpStatusCode.InternalServerError, "Internal server error");
#endif
                }
                catch (Exception err2)
                {
                    LogWriter.Write(this, LogPrio.Fatal, "Failed to respond on message with Internal Server Error: " + err2);
                }
            }
        }
コード例 #8
0
        void ProcessRequest(IHttpClientContext context, IHttpRequest request)
        {
            LogWriter.Write(this, LogPrio.Trace, "Processing request...");

            IHttpResponse response = request.CreateResponse(context);

            try
            {
                // load cookies if they exist.
                RequestCookies cookies = request.Headers["cookie"] != null
                                             ? new RequestCookies(request.Headers["cookie"])
                                             : new RequestCookies(string.Empty);
                request.SetCookies(cookies);

                // Create a request signature
                HttpRequestSignature signature = new HttpRequestSignature(request);

                // Look for a signature match in our handlers
                bool found = false;
                for (int i = 0; i < _requestHandlers.Length; i++)
                {
                    HttpRequestHandler handler = _requestHandlers[i];

                    if (signature == handler.Signature)
                    {
                        FireRequestCallback(context, request, response, handler.Callback);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    // No registered handler matched this request's signature
                    if (_notFoundHandler != null)
                    {
                        FireRequestCallback(context, request, response, _notFoundHandler);
                    }
                    else
                    {
                        // Send a default 404 response
                        try
                        {
                            response.Status = HttpStatusCode.NotFound;
                            response.Reason = String.Format("No request handler registered for Method=\"{0}\", Content-Type=\"{1}\", Path=\"{2}\"",
                                                            signature.Method, signature.ContentType, signature.Path);
                            string notFoundResponse = "<html><head><title>Page Not Found</title></head><body><h3>" + response.Reason + "</h3></body></html>";
                            byte[] buffer           = System.Text.Encoding.UTF8.GetBytes(notFoundResponse);
                            response.Body.Write(buffer, 0, buffer.Length);
                            response.Send();
                        }
                        catch (Exception) { }
                    }
                }
            }
            catch (Exception err)
            {
                ThrowException(err);

                bool errorResponse = true;

                Exception e = err;
                while (e != null)
                {
                    if (e is SocketException)
                    {
                        errorResponse = false;
                        break;
                    }

                    e = e.InnerException;
                }

                if (errorResponse)
                {
                    try
                    {
#if DEBUG
                        context.Respond(HttpHelper.HTTP11, HttpStatusCode.InternalServerError, "Internal server error", err.ToString(), "text/plain");
#else
                        context.Respond(HttpHelper.HTTP10, HttpStatusCode.InternalServerError, "Internal server error");
#endif
                    }
                    catch (Exception err2)
                    {
                        LogWriter.Write(this, LogPrio.Fatal, "Failed to respond on message with Internal Server Error: " + err2);
                    }
                }
            }

            request.Clear();
            LogWriter.Write(this, LogPrio.Trace, "...done processing request.");
        }