use of org.apache.http.impl.cookie.BasicClientCookie in project lucene-solr by apache.
the class SolrPortAwareCookieSpecTest method testDomainValidate2.
@Test
public void testDomainValidate2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
cookie.setDomain(".somedomain.com");
h.validate(cookie, origin);
cookie.setDomain(".otherdomain.com");
try {
h.validate(cookie, origin);
Assert.fail("MalformedCookieException should have been thrown");
} catch (final MalformedCookieException ex) {
// expected
}
cookie.setDomain("www.otherdomain.com");
try {
h.validate(cookie, origin);
Assert.fail("MalformedCookieException should have been thrown");
} catch (final MalformedCookieException ex) {
// expected
}
}
use of org.apache.http.impl.cookie.BasicClientCookie in project lucene-solr by apache.
the class SolrPortAwareCookieSpecTest method testDomainValidate3.
@Test
public void testDomainValidate3() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
cookie.setDomain(".a.com");
h.validate(cookie, origin);
cookie.setDomain(".com");
try {
h.validate(cookie, origin);
Assert.fail("MalformedCookieException should have been thrown");
} catch (final MalformedCookieException ex) {
// expected
}
}
use of org.apache.http.impl.cookie.BasicClientCookie in project spring-framework by spring-projects.
the class MockWebResponseBuilder method createCookie.
static com.gargoylesoftware.htmlunit.util.Cookie createCookie(Cookie cookie) {
Date expires = null;
if (cookie.getMaxAge() > -1) {
expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000);
}
BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue());
result.setDomain(cookie.getDomain());
result.setComment(cookie.getComment());
result.setExpiryDate(expires);
result.setPath(cookie.getPath());
result.setSecure(cookie.getSecure());
if (cookie.isHttpOnly()) {
result.setAttribute("httponly", "true");
}
return new com.gargoylesoftware.htmlunit.util.Cookie(result);
}
use of org.apache.http.impl.cookie.BasicClientCookie in project sling by apache.
the class ITMDCFilter method testWihCustomData.
@Test
public void testWihCustomData() throws Exception {
RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());
//Create test config via servlet
executor.execute(rb.buildGetRequest("/mdc", "createTestConfig", "true"));
TimeUnit.SECONDS.sleep(1);
//Pass custom cookie
BasicClientCookie cookie = new BasicClientCookie("mdc-test-cookie", "foo-test-cookie");
cookie.setPath("/");
cookie.setDomain("localhost");
httpClient.getCookieStore().addCookie(cookie);
//Execute request
RequestExecutor result = executor.execute(rb.buildGetRequest("/mdc", "mdc-test-param", "foo-test-param", "ignored-param", "ignored-value").withHeader("X-Forwarded-For", "foo-forwarded-for").withHeader("mdc-test-header", "foo-test-header"));
JsonObject jb = Json.createReader(new StringReader(result.getContent())).readObject();
log.info("Response {}", result.getContent());
assertEquals("/mdc", jb.getString("req.requestURI"));
assertEquals(ServerConfiguration.getServerUrl() + "/mdc", jb.getString("req.requestURL"));
assertEquals("foo-forwarded-for", jb.getString("req.xForwardedFor"));
assertEquals("foo-test-header", jb.getString("mdc-test-header"));
assertEquals("foo-test-param", jb.getString("mdc-test-param"));
assertEquals("foo-test-cookie", jb.getString("mdc-test-cookie"));
//Only configured params must be returned
assertFalse(jb.containsKey("ignored-param"));
}
use of org.apache.http.impl.cookie.BasicClientCookie in project Lucee by lucee.
the class HTTPEngine4Impl method addCookie.
public static void addCookie(CookieStore cookieStore, String domain, String name, String value, String path, String charset) {
if (ReqRspUtil.needEncoding(name, false))
name = ReqRspUtil.encode(name, charset);
if (ReqRspUtil.needEncoding(value, false))
value = ReqRspUtil.encode(value, charset);
BasicClientCookie cookie = new BasicClientCookie(name, value);
if (!StringUtil.isEmpty(domain, true))
cookie.setDomain(domain);
if (!StringUtil.isEmpty(path, true))
cookie.setPath(path);
cookieStore.addCookie(cookie);
}
Aggregations