Skip to content

Instantly share code, notes, and snippets.

@InputNeuron
Created June 21, 2016 17:32
Show Gist options
  • Select an option

  • Save InputNeuron/b5d242e5cbdf55442d6e063ff935bc71 to your computer and use it in GitHub Desktop.

Select an option

Save InputNeuron/b5d242e5cbdf55442d6e063ff935bc71 to your computer and use it in GitHub Desktop.
ResponseDescriptor responseDescriptor
= new ResponseDescriptor.Builder()
.withStatus(301)
.withHeader("Location", "http://httpbin.org/cookies/set?cat=dog")
.build();
String url = String.format( "http://localhost.localdomain:%s/evaluate?response=%s", webserverPort.getPort(), responseDescriptor.toParam() );
HttpRequest httpRequest
= httpRequestBuilder
.get(url)
.withCookie(new Cookie.Builder("foo", "bar")
.setDomain("localhost.localdomain")
.build())
.withCookie(new Cookie.Builder("cat", "dog")
.setDomain("httpbin.org")
.build())
.execute()
.connect();
assertEquals("[Cookie{name='foo', value='bar', path=Optional[/], domain=Optional[localhost.localdomain], httpOnly=true, secure=false, maxAge=Optional[-1]}, Cookie{name='cat', value='dog', path=Optional[/], domain=Optional[httpbin.org], httpOnly=true, secure=false, maxAge=Optional[-1]}]",
httpRequest.getEffectiveCookies().toString());
assertEquals("{\n" +
" \"cookies\": {\n" +
" \"cat\": \"dog\"\n" +
" }\n" +
"}\n",
httpRequest.getContentWithEncoding());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment