crawl-anywhere icon indicating copy to clipboard operation
crawl-anywhere copied to clipboard

HttpLoader does not fully support cookies

Open grimsa opened this issue 9 years ago • 1 comments

In fr.eolya.utils.http.HttpLoader.getAuthCookies method:

        // A CookieStore object is created
        CookieStore cookieStore = new BasicCookieStore();
        HttpContext localContext = new BasicHttpContext();

        // ... and set
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        /* ... */

        // ... and populated
        HttpResponse response = httpClient.execute(httpPost, localContext);

        /* ... */

        // However this gets a different (empty) CookieStore object, thus returning no cookies!
        List<Cookie> cookies = httpClient.getCookieStore().getCookies();

grimsa avatar Aug 11 '15 17:08 grimsa

In fr.eolya.utils.http.HttpLoader.getHttpClient(String) method when a CookieStore is populated, the Domain for the cookies is not set, making them not be used later when making HTTP requests. The current code should be fixed:

    BasicClientCookie cookie = new BasicClientCookie(pairs.getKey(), pairs.getValue());
    //cookie.setDomain("your domain");                     // <-- this should be implemented properly
    cookie.setPath("/");
    cookieStore.addCookie(cookie);

grimsa avatar Aug 11 '15 18:08 grimsa