/// <summary>Adds valid Port attribute value, e.g.</summary> /// <remarks>Adds valid Port attribute value, e.g. "8000,8001,8002"</remarks> protected internal override void FormatCookieAsVer(CharArrayBuffer buffer, Apache.Http.Cookie.Cookie cookie, int version) { base.FormatCookieAsVer(buffer, cookie, version); // format port attribute if (cookie is ClientCookie) { // Test if the port attribute as set by the origin server is not blank string s = ((ClientCookie)cookie).GetAttribute(ClientCookie.PortAttr); if (s != null) { buffer.Append("; $Port"); buffer.Append("=\""); if (s.Trim().Length > 0) { int[] ports = cookie.GetPorts(); if (ports != null) { int len = ports.Length; for (int i = 0; i < len; i++) { if (i > 0) { buffer.Append(","); } buffer.Append(Sharpen.Extensions.ToString(ports[i])); } } } buffer.Append("\""); } } }
/// <summary>Match cookie port attribute.</summary> /// <remarks> /// Match cookie port attribute. If the Port attribute is not specified /// in header, the cookie can be sent to any port. Otherwise, the request port /// must be in the cookie's port list. /// </remarks> public virtual bool Match(Apache.Http.Cookie.Cookie cookie, CookieOrigin origin) { Args.NotNull(cookie, "Cookie"); Args.NotNull(origin, "Cookie origin"); int port = origin.GetPort(); if (cookie is ClientCookie && ((ClientCookie)cookie).ContainsAttribute(ClientCookie .PortAttr)) { if (cookie.GetPorts() == null) { // Invalid cookie state: port not specified return(false); } if (!PortMatch(port, cookie.GetPorts())) { return(false); } } return(true); }
/// <summary>Validate cookie port attribute.</summary> /// <remarks> /// Validate cookie port attribute. If the Port attribute was specified /// in header, the request port must be in cookie's port list. /// </remarks> /// <exception cref="Apache.Http.Cookie.MalformedCookieException"></exception> public virtual void Validate(Apache.Http.Cookie.Cookie cookie, CookieOrigin origin ) { Args.NotNull(cookie, "Cookie"); Args.NotNull(origin, "Cookie origin"); int port = origin.GetPort(); if (cookie is ClientCookie && ((ClientCookie)cookie).ContainsAttribute(ClientCookie .PortAttr)) { if (!PortMatch(port, cookie.GetPorts())) { throw new CookieRestrictionViolationException("Port attribute violates RFC 2965: " + "Request port not found in cookie's port list."); } } }