public virtual void RegisterAttribHandler(string name, CookieAttributeHandler handler ) { Args.NotNull(name, "Attribute name"); Args.NotNull(handler, "Attribute handler"); this.attribHandlerMap.Put(name, handler); }
/// <exception cref="Apache.Http.Cookie.MalformedCookieException"></exception> protected internal virtual IList <Apache.Http.Cookie.Cookie> Parse(HeaderElement[] elems, CookieOrigin origin) { IList <Apache.Http.Cookie.Cookie> cookies = new AList <Apache.Http.Cookie.Cookie>(elems .Length); foreach (HeaderElement headerelement in elems) { string name = headerelement.GetName(); string value = headerelement.GetValue(); if (name == null || name.Length == 0) { throw new MalformedCookieException("Cookie name may not be empty"); } BasicClientCookie cookie = new BasicClientCookie(name, value); cookie.SetPath(GetDefaultPath(origin)); cookie.SetDomain(GetDefaultDomain(origin)); // cycle through the parameters NameValuePair[] attribs = headerelement.GetParameters(); for (int j = attribs.Length - 1; j >= 0; j--) { NameValuePair attrib = attribs[j]; string s = attrib.GetName().ToLower(Sharpen.Extensions.GetEnglishCulture()); cookie.SetAttribute(s, attrib.GetValue()); CookieAttributeHandler handler = FindAttribHandler(s); if (handler != null) { handler.Parse(cookie, attrib.GetValue()); } } cookies.AddItem(cookie); } return(cookies); }
/// <summary> /// Gets attribute handler /// <see cref="Apache.Http.Cookie.CookieAttributeHandler">Apache.Http.Cookie.CookieAttributeHandler /// </see> /// for the /// given attribute. /// </summary> /// <param name="name">attribute name. e.g. Domain, Path, etc.</param> /// <exception cref="System.InvalidOperationException"> /// if handler not found for the /// specified attribute. /// </exception> protected internal virtual CookieAttributeHandler GetAttribHandler(string name) { CookieAttributeHandler handler = FindAttribHandler(name); if (handler == null) { throw new InvalidOperationException("Handler not registered for " + name + " attribute." ); } else { return(handler); } }
/// <exception cref="Apache.Http.Cookie.MalformedCookieException"></exception> private IList <Apache.Http.Cookie.Cookie> CreateCookies(HeaderElement[] elems, CookieOrigin origin) { IList <Apache.Http.Cookie.Cookie> cookies = new AList <Apache.Http.Cookie.Cookie>(elems .Length); foreach (HeaderElement headerelement in elems) { string name = headerelement.GetName(); string value = headerelement.GetValue(); if (name == null || name.Length == 0) { throw new MalformedCookieException("Cookie name may not be empty"); } BasicClientCookie2 cookie = new BasicClientCookie2(name, value); cookie.SetPath(GetDefaultPath(origin)); cookie.SetDomain(GetDefaultDomain(origin)); cookie.SetPorts(new int[] { origin.GetPort() }); // cycle through the parameters NameValuePair[] attribs = headerelement.GetParameters(); // Eliminate duplicate attributes. The first occurrence takes precedence // See RFC2965: 3.2 Origin Server Role IDictionary <string, NameValuePair> attribmap = new Dictionary <string, NameValuePair >(attribs.Length); for (int j = attribs.Length - 1; j >= 0; j--) { NameValuePair param = attribs[j]; attribmap.Put(param.GetName().ToLower(Sharpen.Extensions.GetEnglishCulture()), param ); } foreach (KeyValuePair <string, NameValuePair> entry in attribmap.EntrySet()) { NameValuePair attrib = entry.Value; string s = attrib.GetName().ToLower(Sharpen.Extensions.GetEnglishCulture()); cookie.SetAttribute(s, attrib.GetValue()); CookieAttributeHandler handler = FindAttribHandler(s); if (handler != null) { handler.Parse(cookie, attrib.GetValue()); } } cookies.AddItem(cookie); } return(cookies); }
public PublicSuffixFilter(CookieAttributeHandler wrapped) { this.wrapped = wrapped; }