webmetrics / browsermob-proxy

NOTICE: this project has been forked and is being maintained at https://github.com/lightbody/browsermob-proxy
https://github.com/lightbody/browsermob-proxy
Apache License 2.0
232 stars 763 forks source link

get secure cookies #119

Closed moose007 closed 10 years ago

moose007 commented 10 years ago

Hi,

great project.

I cant seem to get a hold of cookies that are secure.

Here's a unit test:

@Test

public void testCookiesAreCapturedWhenRequested() throws IOException {
    proxy.setCaptureContent(true);
    proxy.newHar("Test");

    BasicClientCookie cookie = new BasicClientCookie("foo", "bar");
    cookie.setDomain("127.0.0.1");
    cookie.setPath("/");
    client.getCookieStore().addCookie(cookie);

    for (int i=0; i<20; i++){
         cookie = new BasicClientCookie("foo" + i, "bar" + i);
         cookie.setDomain("127.0.0.1");
         cookie.setPath("/");
         cookie.setSecure(true);
         client.getCookieStore().addCookie(cookie);
    }

    // set the cookie on the server side
    String body = IOUtils.readFully(client.execute(new HttpGet("http://127.0.0.1:8080/echo/")).getEntity().getContent());
    System.out.println(body);

    Har har = proxy.getHar();
    HarEntry entry = har.getLog().getEntries().get(0);

    System.out.println(entry.getRequest().getCookies().size());
    HarCookie harCookie = entry.getRequest().getCookies().get(0);
    Assert.assertEquals("foo", harCookie.getName());
    Assert.assertEquals("bar", harCookie.getValue());
}

When cookie.setSecure(true): Method: GET Request Headers: Host: 127.0.0.1:8080 User-Agent: Apache-HttpClient/4.2.3 (java 1.5) Cookie: foo=bar Cookie2: $Version=1 Connection: keep-alive

1

when cookie.setSecure(false): Method: GET Request Headers: Host: 127.0.0.1:8080 User-Agent: Apache-HttpClient/4.2.3 (java 1.5) Cookie: foo=bar; foo0=bar0; foo1=bar1; foo10=bar10; foo11=bar11; foo12=bar12; foo13=bar13; foo14=bar14; foo15=bar15; foo16=bar16; foo17=bar17; foo18=bar18; foo19=bar19; foo2=bar2; foo3=bar3; foo4=bar4; foo5=bar5; foo6=bar6; foo7=bar7; foo8=bar8; foo9=bar9 Cookie2: $Version=1 Connection: keep-alive

21

lightbody commented 10 years ago

Closing this out since a duplicate was submitted to the lightbody/browsermob-proxy repo, which is where I'm doing active dev.