SetCookies() public method

Cookies
public SetCookies ( RequestCookies cookies ) : void
cookies RequestCookies the cookies
return void
Example #1
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
            }
        }
        private void ProcessRequest(HttpClientContext context, HttpRequest request)
        {
            HttpResponse 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);
                }

            }
        }