Search in sources :

Example 1 with CookieVersionSupport

use of org.apache.commons.httpclient.cookie.CookieVersionSupport in project tdi-studio-se by Talend.

the class HttpMethodBase method processResponseHeaders.

/**
     * This method is invoked immediately after 
     * {@link #readResponseHeaders(HttpState,HttpConnection)} and can be overridden by
     * sub-classes in order to provide custom response headers processing.

     * <p>
     * This implementation will handle the <tt>Set-Cookie</tt> and
     * <tt>Set-Cookie2</tt> headers, if any, adding the relevant cookies to
     * the given {@link HttpState}.
     * </p>
     *
     * @param state the {@link HttpState state} information associated with this method
     * @param conn the {@link HttpConnection connection} used to execute
     *        this HTTP method
     *
     * @see #readResponse
     * @see #readResponseHeaders
     */
protected void processResponseHeaders(HttpState state, HttpConnection conn) {
    LOG.trace("enter HttpMethodBase.processResponseHeaders(HttpState, " + "HttpConnection)");
    CookieSpec parser = getCookieSpec(state);
    // process set-cookie headers
    Header[] headers = getResponseHeaderGroup().getHeaders("set-cookie");
    processCookieHeaders(parser, headers, state, conn);
    // see if the cookie spec supports cookie versioning.
    if (parser instanceof CookieVersionSupport) {
        CookieVersionSupport versupport = (CookieVersionSupport) parser;
        if (versupport.getVersion() > 0) {
            // process set-cookie2 headers.
            // Cookie2 will replace equivalent Cookie instances
            headers = getResponseHeaderGroup().getHeaders("set-cookie2");
            processCookieHeaders(parser, headers, state, conn);
        }
    }
}
Also used : CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) CookieVersionSupport(org.apache.commons.httpclient.cookie.CookieVersionSupport)

Example 2 with CookieVersionSupport

use of org.apache.commons.httpclient.cookie.CookieVersionSupport in project zaproxy by zaproxy.

the class HttpMethodBase method addCookieRequestHeader.

/**
 * Generates <tt>Cookie</tt> request headers for those {@link Cookie cookie}s
 * that match the given host, port and path.
 *
 * @param state the {@link HttpState state} information associated with this method
 * @param conn the {@link HttpConnection connection} used to execute
 *        this HTTP method
 *
 * @throws IOException if an I/O (transport) error occurs. Some transport exceptions
 *                     can be recovered from.
 * @throws HttpException  if a protocol exception occurs. Usually protocol exceptions
 *                    cannot be recovered from.
 */
protected void addCookieRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException {
    LOG.trace("enter HttpMethodBase.addCookieRequestHeader(HttpState, " + "HttpConnection)");
    Header[] cookieheaders = getRequestHeaderGroup().getHeaders("Cookie");
    for (int i = 0; i < cookieheaders.length; i++) {
        Header cookieheader = cookieheaders[i];
        if (cookieheader.isAutogenerated()) {
            getRequestHeaderGroup().removeHeader(cookieheader);
        }
    }
    CookieSpec matcher = getCookieSpec(state);
    String host = this.params.getVirtualHost();
    if (host == null) {
        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)) {
            // In strict mode put all cookies on the same header
            putAllCookiesInASingleHeader(host, matcher, cookies);
        } else {
            // In non-strict mode put each cookie on a separate header
            for (int i = 0; i < cookies.length; i++) {
                String s = matcher.formatCookie(cookies[i]);
                getRequestHeaderGroup().addHeader(new Header(HttpHeader.COOKIE, s, true));
            }
        }
        if (matcher instanceof CookieVersionSupport) {
            CookieVersionSupport versupport = (CookieVersionSupport) matcher;
            int ver = versupport.getVersion();
            boolean needVersionHeader = false;
            for (int i = 0; i < cookies.length; i++) {
                if (ver != cookies[i].getVersion()) {
                    needVersionHeader = true;
                }
            }
            if (needVersionHeader) {
                // Advertise cookie version support
                getRequestHeaderGroup().addHeader(versupport.getVersionHeader());
            }
        }
    }
}
Also used : HttpHeader(org.parosproxy.paros.network.HttpHeader) CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) CookieVersionSupport(org.apache.commons.httpclient.cookie.CookieVersionSupport)

Example 3 with CookieVersionSupport

use of org.apache.commons.httpclient.cookie.CookieVersionSupport in project zaproxy by zaproxy.

the class HttpMethodBase method processResponseHeaders.

/**
 * This method is invoked immediately after
 * {@link #readResponseHeaders(HttpState,HttpConnection)} and can be overridden by
 * sub-classes in order to provide custom response headers processing.
 *
 * <p>
 * This implementation will handle the <tt>Set-Cookie</tt> and
 * <tt>Set-Cookie2</tt> headers, if any, adding the relevant cookies to
 * the given {@link HttpState}.
 * </p>
 *
 * @param state the {@link HttpState state} information associated with this method
 * @param conn the {@link HttpConnection connection} used to execute
 *        this HTTP method
 *
 * @see #readResponse
 * @see #readResponseHeaders
 */
protected void processResponseHeaders(HttpState state, HttpConnection conn) {
    LOG.trace("enter HttpMethodBase.processResponseHeaders(HttpState, " + "HttpConnection)");
    CookieSpec parser = getCookieSpec(state);
    // process set-cookie headers
    Header[] headers = getResponseHeaderGroup().getHeaders("set-cookie");
    processCookieHeaders(parser, headers, state, conn);
    // see if the cookie spec supports cookie versioning.
    if (parser instanceof CookieVersionSupport) {
        CookieVersionSupport versupport = (CookieVersionSupport) parser;
        if (versupport.getVersion() > 0) {
            // process set-cookie2 headers.
            // Cookie2 will replace equivalent Cookie instances
            headers = getResponseHeaderGroup().getHeaders("set-cookie2");
            processCookieHeaders(parser, headers, state, conn);
        }
    }
}
Also used : HttpHeader(org.parosproxy.paros.network.HttpHeader) CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) CookieVersionSupport(org.apache.commons.httpclient.cookie.CookieVersionSupport)

Example 4 with CookieVersionSupport

use of org.apache.commons.httpclient.cookie.CookieVersionSupport in project tdi-studio-se by Talend.

the class HttpMethodBase method addCookieRequestHeader.

/**
     * Generates <tt>Cookie</tt> request headers for those {@link Cookie cookie}s
     * that match the given host, port and path.
     *
     * @param state the {@link HttpState state} information associated with this method
     * @param conn the {@link HttpConnection connection} used to execute
     *        this HTTP method
     *
     * @throws IOException if an I/O (transport) error occurs. Some transport exceptions
     *                     can be recovered from.
     * @throws HttpException  if a protocol exception occurs. Usually protocol exceptions 
     *                    cannot be recovered from.
     */
protected void addCookieRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException {
    LOG.trace("enter HttpMethodBase.addCookieRequestHeader(HttpState, " + "HttpConnection)");
    Header[] cookieheaders = getRequestHeaderGroup().getHeaders("Cookie");
    for (int i = 0; i < cookieheaders.length; i++) {
        Header cookieheader = cookieheaders[i];
        if (cookieheader.isAutogenerated()) {
            getRequestHeaderGroup().removeHeader(cookieheader);
        }
    }
    CookieSpec matcher = getCookieSpec(state);
    String host = this.params.getVirtualHost();
    if (host == null) {
        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)) {
            // In strict mode put all cookies on the same header
            String s = matcher.formatCookies(cookies);
            getRequestHeaderGroup().addHeader(new Header("Cookie", s, true));
        } else {
            // In non-strict mode put each cookie on a separate header
            for (int i = 0; i < cookies.length; i++) {
                String s = matcher.formatCookie(cookies[i]);
                getRequestHeaderGroup().addHeader(new Header("Cookie", s, true));
            }
        }
        if (matcher instanceof CookieVersionSupport) {
            CookieVersionSupport versupport = (CookieVersionSupport) matcher;
            int ver = versupport.getVersion();
            boolean needVersionHeader = false;
            for (int i = 0; i < cookies.length; i++) {
                if (ver != cookies[i].getVersion()) {
                    needVersionHeader = true;
                }
            }
            if (needVersionHeader) {
                // Advertise cookie version support
                getRequestHeaderGroup().addHeader(versupport.getVersionHeader());
            }
        }
    }
}
Also used : CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) CookieVersionSupport(org.apache.commons.httpclient.cookie.CookieVersionSupport)

Aggregations

CookieSpec (org.apache.commons.httpclient.cookie.CookieSpec)4 CookieVersionSupport (org.apache.commons.httpclient.cookie.CookieVersionSupport)4 HttpHeader (org.parosproxy.paros.network.HttpHeader)2