コード例 #1
0
        public IHttpResponse Handle(IHttpRequest request)
        {
            var newSessionId = string.Empty;

            if (!request.Cookies.Has($"{Stringifier.SID}"))
            {
                newSessionId    = Guid.NewGuid().ToString();
                request.Session = HttpSessionStore.Get(newSessionId);
            }

            var response = this.handler(request);

            foreach (var cookie in request.Cookies)
            {
                if (cookie.IsNew)
                {
                    response.Headers.Add(new HttpHeader("Set-Cookie", cookie.ToString()));
                }
            }

            if (!response.Headers.Has("Content-Type"))
            {
                response.Headers.Add(new HttpHeader("Content-Type", "text/html"));
            }

            if (!string.IsNullOrWhiteSpace(newSessionId))
            {
                response.Headers.Add(new HttpHeader("Set-Cookie", $"{Stringifier.SID}={newSessionId}; HttpOnly; path=/"));
            }

            return(response);
        }
コード例 #2
0
        private void ParseSession()
        {
            if (this.Cookies.Has(Stringifier.SID))
            {
                var cookie = this.Cookies[Stringifier.SID];

                this.Session = HttpSessionStore.Get(cookie.Value);
            }
        }