コード例 #1
0
        public override IList <Header> FormatCookies(IList <Apache.Http.Cookie.Cookie> cookies
                                                     )
        {
            Args.NotEmpty(cookies, "List of cookies");
            CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.Count);

            buffer.Append(SM.Cookie);
            buffer.Append(": ");
            for (int i = 0; i < cookies.Count; i++)
            {
                Apache.Http.Cookie.Cookie cookie = cookies[i];
                if (i > 0)
                {
                    buffer.Append("; ");
                }
                buffer.Append(cookie.GetName());
                string s = cookie.GetValue();
                if (s != null)
                {
                    buffer.Append("=");
                    buffer.Append(s);
                }
            }
            IList <Header> headers = new AList <Header>(1);

            headers.AddItem(new BufferedHeader(buffer));
            return(headers);
        }
コード例 #2
0
        /// <exception cref="Apache.Http.Cookie.MalformedCookieException"></exception>
        public override void Validate(Apache.Http.Cookie.Cookie cookie, CookieOrigin origin
                                      )
        {
            Args.NotNull(cookie, "Cookie");
            string name = cookie.GetName();

            if (name.IndexOf(' ') != -1)
            {
                throw new CookieRestrictionViolationException("Cookie name may not contain blanks"
                                                              );
            }
            if (name.StartsWith("$"))
            {
                throw new CookieRestrictionViolationException("Cookie name may not start with $");
            }
            base.Validate(cookie, origin);
        }
コード例 #3
0
 /// <summary>
 /// Return a string suitable for sending in a <tt>"Cookie"</tt> header
 /// as defined in RFC 2109 for backward compatibility with cookie version 0
 /// </summary>
 /// <param name="buffer">The char array buffer to use for output</param>
 /// <param name="cookie">
 /// The
 /// <see cref="Apache.Http.Cookie.Cookie">Apache.Http.Cookie.Cookie</see>
 /// to be formatted as string
 /// </param>
 /// <param name="version">The version to use.</param>
 protected internal virtual void FormatCookieAsVer(CharArrayBuffer buffer, Apache.Http.Cookie.Cookie
                                                   cookie, int version)
 {
     FormatParamAsVer(buffer, cookie.GetName(), cookie.GetValue(), version);
     if (cookie.GetPath() != null)
     {
         if (cookie is ClientCookie && ((ClientCookie)cookie).ContainsAttribute(ClientCookie
                                                                                .PathAttr))
         {
             buffer.Append("; ");
             FormatParamAsVer(buffer, "$Path", cookie.GetPath(), version);
         }
     }
     if (cookie.GetDomain() != null)
     {
         if (cookie is ClientCookie && ((ClientCookie)cookie).ContainsAttribute(ClientCookie
                                                                                .DomainAttr))
         {
             buffer.Append("; ");
             FormatParamAsVer(buffer, "$Domain", cookie.GetDomain(), version);
         }
     }
 }
コード例 #4
0
		public override IList<Header> FormatCookies(IList<Apache.Http.Cookie.Cookie> cookies
			)
		{
			Args.NotEmpty(cookies, "List of cookies");
			CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.Count);
			buffer.Append(SM.Cookie);
			buffer.Append(": ");
			for (int i = 0; i < cookies.Count; i++)
			{
				Apache.Http.Cookie.Cookie cookie = cookies[i];
				if (i > 0)
				{
					buffer.Append("; ");
				}
				string cookieName = cookie.GetName();
				string cookieValue = cookie.GetValue();
				if (cookie.GetVersion() > 0 && !IsQuoteEnclosed(cookieValue))
				{
					BasicHeaderValueFormatter.Instance.FormatHeaderElement(buffer, new BasicHeaderElement
						(cookieName, cookieValue), false);
				}
				else
				{
					// Netscape style cookies do not support quoted values
					buffer.Append(cookieName);
					buffer.Append("=");
					if (cookieValue != null)
					{
						buffer.Append(cookieValue);
					}
				}
			}
			IList<Header> headers = new AList<Header>(1);
			headers.AddItem(new BufferedHeader(buffer));
			return headers;
		}
コード例 #5
0
        private static string FormatCooke(Apache.Http.Cookie.Cookie cookie)
        {
            StringBuilder buf = new StringBuilder();

            buf.Append(cookie.GetName());
            buf.Append("=\"");
            string v = cookie.GetValue();

            if (v.Length > 100)
            {
                v = Sharpen.Runtime.Substring(v, 0, 100) + "...";
            }
            buf.Append(v);
            buf.Append("\"");
            buf.Append(", version:");
            buf.Append(Sharpen.Extensions.ToString(cookie.GetVersion()));
            buf.Append(", domain:");
            buf.Append(cookie.GetDomain());
            buf.Append(", path:");
            buf.Append(cookie.GetPath());
            buf.Append(", expiry:");
            buf.Append(cookie.GetExpiryDate());
            return(buf.ToString());
        }