Пример #1
0
        private string ReadCookie(IHttpRequestDescriptor request)
        {
            var cookie = request.GetHeader("Cookie");

            if (string.IsNullOrWhiteSpace(cookie))
            {
                return(null);
            }
            var headerStart = cookie.IndexOf(CookieName);

            if (headerStart == -1)
            {
                return(string.Empty);
            }
            var eq = cookie.IndexOf('=', headerStart);

            if (eq == -1)
            {
                return(string.Empty);
            }
            if (eq == cookie.Length - 1)
            {
                return(string.Empty);
            }
            var finish = cookie.IndexOfAny(new[] { ',', ' ', ';' }, eq);

            if (finish == -1)
            {
                finish = cookie.Length;
            }
            var result = cookie.Substring(eq + 1, finish - (eq + 1));

            return(Uri.UnescapeDataString(result));
        }
Пример #2
0
        private TrustedOrigin GetTrust(IHttpRequestDescriptor request)
        {
            var origin = request.GetHeader("Origin") ?? "";

            return(TrustedOrigins.FirstOrDefault(_ => _.IsMatch(request.RemoteEndPoint, request.LocalEndPoint, origin)));
        }