use of io.vertx.core.http.Cookie in project vertx-web by vert-x3.
the class CookieHandlerTest method testCookiesChangedInHandler.
@Test
public void testCookiesChangedInHandler() throws Exception {
router.route().handler(rc -> {
assertEquals(3, rc.request().cookieCount());
assertEquals("bar", rc.request().getCookie("foo").getValue());
assertEquals("blibble", rc.request().getCookie("wibble").getValue());
assertEquals("flop", rc.request().getCookie("plop").getValue());
rc.response().removeCookie("plop");
// the expected number of elements should remain the same as we're sending an invalidate cookie back
assertEquals(3, rc.request().cookieCount());
rc.next();
});
router.route().handler(rc -> {
assertEquals("bar", rc.request().getCookie("foo").getValue());
assertEquals("blibble", rc.request().getCookie("wibble").getValue());
assertNotNull(rc.request().getCookie("plop"));
rc.response().addCookie(Cookie.cookie("fleeb", "floob"));
assertEquals(4, rc.request().cookieCount());
assertNull(rc.response().removeCookie("blarb"));
assertEquals(4, rc.request().cookieCount());
Cookie foo = rc.request().getCookie("foo");
foo.setValue("blah");
rc.response().end();
});
testRequest(HttpMethod.GET, "/", req -> req.headers().set("Cookie", "foo=bar; wibble=blibble; plop=flop"), resp -> {
List<String> cookies = resp.headers().getAll("set-cookie");
assertEquals(3, cookies.size());
assertTrue(cookies.contains("foo=blah"));
assertTrue(cookies.contains("fleeb=floob"));
boolean found = false;
for (String s : cookies) {
if (s.startsWith("plop")) {
found = true;
assertTrue(s.contains("Max-Age=0"));
assertTrue(s.contains("Expires="));
break;
}
}
assertTrue(found);
}, 200, "OK", null);
}
use of io.vertx.core.http.Cookie in project java-chassis by ServiceComb.
the class CookieAccessItem method appendServerFormattedItem.
@Override
public void appendServerFormattedItem(ServerAccessLogEvent accessLogEvent, StringBuilder builder) {
Map<String, Cookie> cookieMap = accessLogEvent.getRoutingContext().cookieMap();
if (null == cookieMap) {
builder.append(RESULT_NOT_FOUND);
return;
}
for (Cookie cookie : cookieMap.values()) {
if (varName.equals(cookie.getName())) {
builder.append(cookie.getValue());
return;
}
}
builder.append(RESULT_NOT_FOUND);
}
use of io.vertx.core.http.Cookie in project java-chassis by ServiceComb.
the class CookieItemTest method serverFormattedElementOnNotFound.
@Test
public void serverFormattedElementOnNotFound() {
HashMap<String, Cookie> cookieSet = new HashMap<>();
CookieImpl cookie = new CookieImpl("anotherCookieName", COOKIE_VALUE);
cookieSet.put(cookie.getName(), cookie);
Mockito.when(mockContext.cookieCount()).thenReturn(1);
Mockito.when(mockContext.cookieMap()).thenReturn(cookieSet);
accessLogEvent.setRoutingContext(mockContext);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
Assert.assertEquals("-", strBuilder.toString());
}
use of io.vertx.core.http.Cookie in project java-chassis by ServiceComb.
the class CookieItemTest method serverFormattedElement.
@Test
public void serverFormattedElement() {
HashMap<String, Cookie> cookieSet = new HashMap<>();
CookieImpl cookie = new CookieImpl(COOKIE_NAME, COOKIE_VALUE);
cookieSet.put(cookie.getName(), cookie);
when(mockContext.cookieCount()).thenReturn(1);
when(mockContext.cookieMap()).thenReturn(cookieSet);
accessLogEvent.setRoutingContext(mockContext);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
Assert.assertEquals(COOKIE_VALUE, strBuilder.toString());
}
use of io.vertx.core.http.Cookie in project incubator-servicecomb-java-chassis by apache.
the class CookieItemTest method serverFormattedElementOnNotFound.
@Test
public void serverFormattedElementOnNotFound() {
HashMap<String, Cookie> cookieSet = new HashMap<>();
CookieImpl cookie = new CookieImpl("anotherCookieName", COOKIE_VALUE);
cookieSet.put(cookie.getName(), cookie);
Mockito.when(mockContext.cookieCount()).thenReturn(1);
Mockito.when(mockContext.cookieMap()).thenReturn(cookieSet);
accessLogEvent.setRoutingContext(mockContext);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
Assert.assertEquals("-", strBuilder.toString());
}
Aggregations