/// <summary>
        /// Adds the specified cookie.
        /// </summary>
        /// <param name="cookie">The cookie.</param>
        public void Add(IHttpCookie cookie)
        {
            if (cookie == null)
                throw new ArgumentNullException("cookie");

            _items.Add(cookie.Name, cookie);
        }
Пример #2
0
 public RpcHttpCookie(IHttpCookie other) : this()
 {
     name_   = other.Name;
     value_  = other.Value;
     domain_ = other.Domain != null ? new NullableString()
     {
         Value = other.Domain
     } : null;
     path_ = other.Path != null ? new NullableString()
     {
         Value = other.Path
     } : null;
     expires_ = other.Expires != null ? new NullableTimestamp {
         Value = new Google.Protobuf.WellKnownTypes.Timestamp {
             Seconds = other.Expires.Value.ToUnixTimeSeconds()
         }
     } : null;
     secure_ = other.Secure != null ? new NullableBool {
         Value = other.Secure.Value
     } : null;
     httpOnly_ = other.HttpOnly != null ? new NullableBool {
         Value = other.HttpOnly.Value
     } : null;
     sameSite_ = (Types.SameSite)other.SameSite;
     maxAge_   = other.MaxAge != null ? new NullableDouble {
         Value = other.MaxAge.Value
     } : null;
 }
Пример #3
0
 public void Add(IHttpCookie cookie)
 {
     if (cookie != null)
     {
         Items.Add(cookie);
     }
 }
Пример #4
0
 public void Add(IHttpCookie cookie)
 {
     if (cookie != null)
     {
         cookies[cookie.Name] = cookie;
     }
 }
Пример #5
0
 /// <summary>
 /// 将指定的 Cookie 添加到此响应的 Cookie 集合。
 /// </summary>
 /// <param name="cookie">cookie。</param>
 public void AppendCookie(IHttpCookie cookie)
 {
     if (cookie == null)
     {
         return;
     }
     Cookies.Add(cookie.Name, cookie.Value, cookie.Path, cookie.Domain);
 }
 public void SetCookie(string name, IHttpCookie value)
 {
     if (!ContainsCookie(name))
     {
         AddCookie(value);
     }
     cookies[name] = value;
 }
        /// <summary>
        /// Adds the specified cookie.
        /// </summary>
        /// <param name="cookie">The cookie.</param>
        public void Add(IHttpCookie cookie)
        {
            if (cookie == null)
            {
                throw new ArgumentNullException("cookie");
            }

            _items.Add(cookie.Name, cookie);
        }
Пример #8
0
 public void Set(IHttpCookie cookie)
 {
     if (cookie == null)
     {
         return;
     }
     Remove(cookie.Name);
     Add(cookie);
 }
        private void SetSession()
        {
            if (this.Cookies.ContainsKey(SessionCookieKey))
            {
                IHttpCookie cookie    = this.Cookies.Get(SessionCookieKey);
                string      sessionId = cookie.Value;

                this.Session = SessionStore.Get(sessionId);
            }
        }
 public void SetCookie(IHttpCookie cookie)
 {
     if (cookie != null)
     {
         if (ContainsCookie(cookie.Name))
         {
             cookies[cookie.Name] = cookie;
         }
     }
 }
Пример #11
0
        /// <summary>
        /// 获取具有指定名称的 Cookie 值(简化操作,直接获取值,未找到就是null。)。
        /// </summary>
        /// <param name="name">要检索的 Cookie 名称。</param>
        /// <returns>由 name 指定的 IHttpCookie 的Value。</returns>
        public string GetValue(string name)
        {
            IHttpCookie item = this[name];

            if (item == null)
            {
                return(null);
            }
            return(item.Value);
        }
Пример #12
0
        /// <summary>
        /// 获取具有指定数字索引的 Cookie 值(简化操作,直接获取值,未找到就是null。)。
        /// </summary>
        /// <param name="index">要从集合中检索的 Cookie 索引。</param>
        /// <returns>按 index 指定的 IHttpCookie 的Value。</returns>
        public string GetValue(int index)
        {
            IHttpCookie item = this[index];

            if (item == null)
            {
                return(null);
            }
            return(item.Value);
        }
 public void AddCookie(IHttpCookie cookie)
 {
     if (cookie != null)
     {
         if (!ContainsCookie(cookie.Name))
         {
             cookies.Add(cookie.Name, cookie);
         }
     }
 }
 public void AddCookie(IHttpCookie cookie)
 {
     if (!ContainsCookie(cookie.Name))
     {
         cookies.Add(cookie.Name, cookie);
     }
     else
     {
         SetCookie(cookie.Name, cookie);
     }
 }
        public override void Append(IHttpCookie cookie)
        {
            if (cookie is null)
            {
                throw new ArgumentNullException(nameof(cookie));
            }

            if (cookie is not RpcHttpCookie rpcCookie)
            {
                rpcCookie = new RpcHttpCookie(cookie);
            }

            _cookies.Add(rpcCookie);
        }
Пример #16
0
            void OutputHeader(int contentLength = -1)
            {
                System.Text.StringBuilder builder = new System.Text.StringBuilder();
                builder.AppendFormat("HTTP/{0} {1} {2}\r\n", _response.ProtocolVersion.ToString(), _response._statusCode, _response._statusDescription);
                builder.AppendFormat("Date: {0}\r\n", DateTimeExtensions.ToGMT(DateTime.Now));
                bool findConnection    = false;
                bool findContentLength = false;

                foreach (string key in _response._headers.AllKeys)
                {
                    if (Array.Exists(_invalidHeaderNames, p => string.Equals(p, key, StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }
                    if (string.Equals(key, "Connection", StringComparison.OrdinalIgnoreCase))
                    {
                        findConnection = true;
                    }
                    else if (string.Equals(key, "Content-Length", StringComparison.OrdinalIgnoreCase))
                    {
                        findContentLength = true;
                    }
                    if (string.Equals(key, "Server", StringComparison.OrdinalIgnoreCase))
                    {
                        string value = _response._headers[key];
                        //if (!string.IsNullOrEmpty(value))
                        //    value = StringExtensions.Replace(value, "{version}", Host._version, true);
                        _response._headers[key] = value;
                    }
                    builder.AppendFormat("{0}: {1}\r\n", key, _response._headers[key]);
                }
                builder.AppendFormat("Content-Type: {0}; charset={1}\r\n", _response.ContentType, _response._contentEncoding.WebName.ToLower());
                if (contentLength != -1 && !findContentLength)
                {
                    builder.AppendFormat("Content-Length: {0}\r\n", contentLength);
                }

                if (_response._cookies.Count > 0)
                {
                    builder.Append("Set-Cookie: ");
                    foreach (string key in _response._cookies.AllKeys)
                    {
                        IHttpCookie cookie = _response._cookies[key];
                        if (cookie == null)
                        {
                            continue;
                        }

                        builder.AppendFormat("{0}={1}; ", cookie.Name, cookie.Value);
                        if (!string.IsNullOrEmpty(cookie.Path))
                        {
                            builder.AppendFormat("path={0}; ", cookie.Path);
                        }
                        if (!string.IsNullOrEmpty(cookie.Domain))
                        {
                            builder.AppendFormat("domain={0}; ", cookie.Domain);
                        }
                        if (cookie.HttpOnly)
                        {
                            builder.Append("HttpOnly; ");
                        }
                        else
                        {
                            builder.AppendFormat("expires={0}; ", DateTimeExtensions.ToGMT(cookie.Expires, '-'));
                        }
                        builder.AppendLine();
                    }
                }
                if (!findConnection)
                {
                    builder.Append("Connection: close\r\n");
                }

                builder.Append("\r\n");
                _response._headerOutputed = true;
                if (!_response.IsClientConnected && _response._outputStream == null)
                {
                    return;
                }
                byte[] buffer = System.Text.Encoding.ASCII.GetBytes(builder.ToString());
                //Console.WriteLine("OutputHeader length:{0},string.length:{1}",buffer.Length,builder.Length);
                _response._outputStream.Write(buffer, 0, buffer.Length);
            }
Пример #17
0
        public void Add(IHttpCookie cookie)
        {
            CoreValidator.ThrowIfNull(cookie, nameof(cookie));

            this.cookies[cookie.Key] = cookie;
        }
 public void Set(IHttpCookie cookie)
 {
     var item = MapCookie(cookie);
     Items.Set(item);
 }
Пример #19
0
 public void AppendCookie(IHttpCookie cookie)
 {
     _cookies.Add(cookie);
 }
        public void Add(IHttpCookie cookie)
        {
            var item = MapCookie(cookie);

            Items.Add(item);
        }
        private static HttpCookie MapCookie(IHttpCookie cookie)
        {
            var item = new HttpCookie(cookie.Name, cookie.Value);

            item.HttpOnly = cookie.HttpOnly;
            item.Domain = cookie.Domain;
            item.Expires = cookie.Expires;
            item.Path = cookie.Path;
            item.Secure = cookie.Secure;
            //item.Values.Clear();

            //foreach (var key in cookie.Values.AllKeys)
            //    item.Values.Add(key, cookie.Values[key]);
            return item;
        }
        //TODO:
        //public virtual HttpCookieCollection Cookies
        //{
        //    get
        //    {
        //        throw new NotImplementedException();
        //    }
        //}
       
        //public virtual void AddCacheDependency(params CacheDependency[] dependencies)
        //{
        //    throw new NotImplementedException();
        //}
       
        //public virtual void AppendCookie(HttpCookie cookie)
        //{
        //    throw new NotImplementedException();
        //}
       
        //public virtual void SetCookie(HttpCookie cookie)
        //{
        //    throw new NotImplementedException();
        //}


        void IHttpResponse.AppendCookie(IHttpCookie cookie)
        {
            throw new NotImplementedException();
        }
Пример #23
0
 public void Add(IHttpCookie cookie)
 {
     if (cookie != null)
         Items.Add(cookie);
 }
 public void Add(IHttpCookie cookie)
 {
     CoreValidator.ThrowIfNull(cookie, nameof(cookie.Key));
     this.cookies.Add(cookie.Key, cookie);
 }
Пример #25
0
 public void SetCookie(IHttpCookie cookie)
 {
     _cookies.Set(cookie);
 }
Пример #26
0
 public void AddCookie(IHttpCookie cookie)
 {
     CoreValidator.ThrowIfNull(cookie, nameof(cookie));
     this.Cookies.AddCookie(cookie);
 }
Пример #27
0
 public CookieContext(IHttpCookie httpCookie, IEncoder encoder, IDate date)
 {
     _httpCookie = httpCookie;
     _encoder = encoder;
     _date = date;
 }
Пример #28
0
 private void SetResponseSession(IHttpResponse httpResponse, IHttpCookie sessionCookie)
 {
     httpResponse.Cookies.Add(sessionCookie);
 }
Пример #29
0
 /// <summary>
 /// Adds the provided <see cref="IHttpCookie"/>.
 /// To create a cookie, you can use the <see cref="CreateNew"/> method.
 /// </summary>
 /// <param name="cookie">The <see cref="IHttpCookie"/> to add.</param>
 public abstract void Append(IHttpCookie cookie);
 void IHttpResponse.SetCookie(IHttpCookie cookie)
 {
     (this as IHttpResponse).Cookies.Set(cookie);
 }
Пример #31
0
 public void AppendCookie(IHttpCookie cookie)
 {
     _cookies.Add(cookie);
 }
Пример #32
0
 public void Set(IHttpCookie cookie)
 {
     if (cookie == null)
         return;
     Remove(cookie.Name);
     Add(cookie);
 }
Пример #33
0
 public void SetCookie(IHttpCookie cookie)
 {
     _cookies.Set(cookie);
 }
Пример #34
0
 public override void Append(IHttpCookie cookie)
 {
     throw new NotImplementedException();
 }