Search in sources :

Example 1 with CookieSpec

use of org.apache.commons.httpclient.cookie.CookieSpec 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 CookieSpec

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

the class ZapCookieSpecUnitTest method shouldThrowWhenValidatingWithNullCookie.

@Test
void shouldThrowWhenValidatingWithNullCookie() throws MalformedCookieException {
    // Given
    CookieSpec cookieSpec = createCookieSpec();
    Cookie cookie = null;
    // When / Then
    assertThrows(NullPointerException.class, () -> cookieSpec.validate(HOST, PORT, PATH, SECURE, cookie));
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) Test(org.junit.jupiter.api.Test)

Example 3 with CookieSpec

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

the class ZapCookieSpecUnitTest method shouldThrowWhenValidatingWithNullCookieDomain.

@Test
void shouldThrowWhenValidatingWithNullCookieDomain() throws MalformedCookieException {
    // Given
    CookieSpec cookieSpec = createCookieSpec();
    Cookie cookie = new Cookie(null, "name", "value");
    // When / Then
    assertThrows(NullPointerException.class, () -> cookieSpec.validate(HOST, PORT, PATH, SECURE, cookie));
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) Test(org.junit.jupiter.api.Test)

Example 4 with CookieSpec

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

the class ZapCookieSpecUnitTest method shouldThrowWhenValidatingWithEmptyHost.

@Test
void shouldThrowWhenValidatingWithEmptyHost() throws MalformedCookieException {
    // Given
    CookieSpec cookieSpec = createCookieSpec();
    String host = "";
    // When / Then
    assertThrows(IllegalArgumentException.class, () -> cookieSpec.validate(host, PORT, PATH, SECURE, new Cookie()));
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) Test(org.junit.jupiter.api.Test)

Example 5 with CookieSpec

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

the class ZapCookieSpecUnitTest method shouldThrowWhenValidatingWithNullPath.

@Test
void shouldThrowWhenValidatingWithNullPath() throws MalformedCookieException {
    // Given
    CookieSpec cookieSpec = createCookieSpec();
    String path = null;
    // When / Then
    assertThrows(IllegalArgumentException.class, () -> cookieSpec.validate(HOST, PORT, path, SECURE, new Cookie()));
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) CookieSpec(org.apache.commons.httpclient.cookie.CookieSpec) Test(org.junit.jupiter.api.Test)

Aggregations

CookieSpec (org.apache.commons.httpclient.cookie.CookieSpec)12 Cookie (org.apache.commons.httpclient.Cookie)8 Test (org.junit.jupiter.api.Test)8 CookieVersionSupport (org.apache.commons.httpclient.cookie.CookieVersionSupport)4 HttpHeader (org.parosproxy.paros.network.HttpHeader)2