/// <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); }
/// <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); }
/// <exception cref="Apache.Http.Cookie.MalformedCookieException"></exception> public virtual void Parse(SetCookie cookie, string value) { wrapped.Parse(cookie, value); }