public virtual bool Match(Apache.Http.Cookie.Cookie cookie, CookieOrigin origin) { Args.NotNull(cookie, "Cookie"); Args.NotNull(origin, "Cookie origin"); string targetpath = origin.GetPath(); string topmostPath = cookie.GetPath(); if (topmostPath == null) { topmostPath = "/"; } if (topmostPath.Length > 1 && topmostPath.EndsWith("/")) { topmostPath = Sharpen.Runtime.Substring(topmostPath, 0, topmostPath.Length - 1); } bool match = targetpath.StartsWith(topmostPath); // if there is a match and these values are not exactly the same we have // to make sure we're not matcing "/foobar" and "/foo" if (match && targetpath.Length != topmostPath.Length) { if (!topmostPath.EndsWith("/")) { match = (targetpath[topmostPath.Length] == '/'); } } return(match); }
/// <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); } } }
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()); }
/// <exception cref="Apache.Http.Cookie.MalformedCookieException"></exception> public virtual void Validate(Apache.Http.Cookie.Cookie cookie, CookieOrigin origin ) { if (!Match(cookie, origin)) { throw new CookieRestrictionViolationException("Illegal path attribute \"" + cookie .GetPath() + "\". Path of origin: \"" + origin.GetPath() + "\""); } }