host = conn.getHost(); Cookie[] cookies = matcher.match(host, conn.getPort(), getPath(), conn.isSecure(), state.getCookies()); if ((cookies != null) && (cookies.length > 0)) { if (getParams().isParameterTrue(HttpMethodParams.SINGLE_COOKIE_HEADER)) { String s = matcher.formatCookies(cookies); getRequestHeaderGroup().addHeader(new Header("Cookie", s, true)); } else { String s = matcher.formatCookie(cookies[i]); getRequestHeaderGroup().addHeader(new Header("Cookie", s, true));
Cookie[] cookies = null; try { cookies = parser.parse( host, conn.getPort(), Cookie cookie = cookies[j]; try { parser.validate( host, conn.getPort(), if (LOG.isDebugEnabled()) { LOG.debug("Cookie accepted: \"" + parser.formatCookie(cookie) + "\""); LOG.warn("Cookie rejected: \"" + parser.formatCookie(cookie) + "\". " + e.getMessage());
/** * Returns the actual cookie policy * * @param state HTTP state. TODO: to be removed in the future * * @return cookie spec */ private CookieSpec getCookieSpec(final HttpState state) { if (this.cookiespec == null) { int i = state.getCookiePolicy(); if (i == -1) { this.cookiespec = CookiePolicy.getCookieSpec(this.params.getCookiePolicy()); } else { this.cookiespec = CookiePolicy.getSpecByPolicy(i); } this.cookiespec.setValidDateFormats( (Collection)this.params.getParameter(HttpMethodParams.DATE_PATTERNS)); } return this.cookiespec; }
for (int i = 0, m = cookies.size(); i < m; i++) { Cookie cookie = (Cookie) (cookies.get(i)); if (matcher.match(domain, port, path, secure, cookie)) { list.add(cookie);
/** * Return a textual representation of the cookie. * * @return string. */ public String toExternalForm() { CookieSpec spec = CookiePolicy.getCookieSpec(CookiePolicy.RFC_2965); return spec.formatCookie(this); }
host = conn.getHost(); Cookie[] cookies = matcher.match(host, conn.getPort(), getPath(), conn.isSecure(), state.getCookies()); if ((cookies != null) && (cookies.length > 0)) { String s = matcher.formatCookie(cookies[i]); getRequestHeaderGroup().addHeader(new Header(HttpHeader.COOKIE, s, true));
} else if (header.getName().equalsIgnoreCase(RFC2109Spec.SET_COOKIE_KEY)) { return this.rfc2109.parse(host, port, path, secure, header.getValue()); } else { throw new MalformedCookieException("Header name is not valid. " +
return this.rfc2109.formatCookies(cookies);
this.rfc2109.validate(host, port, path, secure, cookie);
} else { return this.rfc2109.match(host, port, path, secure, cookie);
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header as * defined in RFC 2965 * @param cookie a {@link org.apache.commons.httpclient.Cookie} to be formatted as string * @return a string suitable for sending in a <tt>"Cookie"</tt> header. */ public String formatCookie(final Cookie cookie) { LOG.trace("enter RFC2965Spec.formatCookie(Cookie)"); if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof Cookie2) { Cookie2 cookie2 = (Cookie2) cookie; int version = cookie2.getVersion(); final StringBuffer buffer = new StringBuffer(); this.formatter.format(buffer, new NameValuePair("$Version", Integer.toString(version))); buffer.append("; "); doFormatCookie2(cookie2, buffer); return buffer.toString(); } else { // old-style cookies are formatted according to the old rules return this.rfc2109.formatCookie(cookie); } }
String path = uri.getPath(); return cookieSpec.parse(host, port, path, secure, cookieHeaderValue);
return this.rfc2109.formatCookies(cookies);
this.rfc2109.validate(host, port, path, secure, cookie);
/** * Parses the cookies from the given connection and stores them in httpState. * Invalid cookies are ignored and logged. */ private void readCookies(IRtXMASessionClient session, URL url,HttpURLConnection conn) { String headerName=""; for(int i=1;headerName!=null;i++) { headerName = conn.getHeaderFieldKey(i); if(Statics.HTTP_SET_COOKIE.equals(headerName)) { try { Cookie[] cookies = cookieSpec.parse(url.getHost(),getPort(url),url.getPath(),"https".equals(url.getProtocol()),conn.getHeaderField(i)); if(cookies!=null) { for(int j=0;j<cookies.length;j++) { try { cookieSpec.validate(url.getHost(),getPort(url),url.getPath(),"https".equals(url.getProtocol()),cookies[j]); getHttpState(session).addCookie(cookies[j]); if(session!=null && "JSESSIONID".equals(cookies[j].getName())) { session.setId(cookies[j].getName()+"="+cookies[j].getValue()); } } catch (MalformedCookieException e) { log_.log(LogLevel.WARNING,"cookie rejected: \""+cookieSpec.formatCookie(cookies[j])+"\". "+e.getMessage()); } } } } catch (MalformedCookieException e) { log_.log(LogLevel.WARNING,"Invalid cookie header: \""+conn.getHeaderField(i)+"\". "+e.getMessage()); } } } }
host = conn.getHost(); Cookie[] cookies = matcher.match(host, conn.getPort(), getPath(), conn.isSecure(), state.getCookies()); if ((cookies != null) && (cookies.length > 0)) { if (getParams().isParameterTrue(HttpMethodParams.SINGLE_COOKIE_HEADER)) { String s = matcher.formatCookies(cookies); getRequestHeaderGroup().addHeader(new Header("Cookie", s, true)); } else { String s = matcher.formatCookie(cookies[i]); getRequestHeaderGroup().addHeader(new Header("Cookie", s, true));
/** * Returns all cookies which are stored for the given url and session. */ public Cookie[] getCookies(URL url, IRtXMASessionClient session) { Cookie[] cookies = getHttpState(session).getCookies(); if(cookies!=null&&cookies.length>0) { cookies = cookieSpec.match(url.getHost(),getPort(url),url.getPath(),"https".equals(url.getProtocol()),cookies); } return cookies; }
/** * Return a textual representation of the cookie. * * @return string. */ public String toExternalForm() { CookieSpec spec = null; if (getVersion() > 0) { spec = CookiePolicy.getDefaultSpec(); } else { spec = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE); } return spec.formatCookie(this); }
} else if (header.getName().equalsIgnoreCase(RFC2109Spec.SET_COOKIE_KEY)) { return this.rfc2109.parse(host, port, path, secure, header.getValue()); } else { throw new MalformedCookieException("Header name is not valid. " +
return this.rfc2109.formatCookies(cookies);