use of io.vertx.ext.web.impl.CookieImpl in project incubator-servicecomb-java-chassis by apache.
the class CookieItemTest method getFormattedElementOnNotFound.
@Test
public void getFormattedElementOnNotFound() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext mockContext = Mockito.mock(RoutingContext.class);
HashSet<Cookie> cookieSet = new HashSet<>();
String cookieValue = "cookieValue";
CookieImpl cookie = new CookieImpl("anotherCookieName", cookieValue);
cookieSet.add(cookie);
Mockito.when(mockContext.cookieCount()).thenReturn(1);
Mockito.when(mockContext.cookies()).thenReturn(cookieSet);
param.setContextData(mockContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertEquals("-", result);
}
use of io.vertx.ext.web.impl.CookieImpl in project incubator-servicecomb-java-chassis by apache.
the class CookieItemTest method getFormattedElement.
@Test
public void getFormattedElement() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext mockContext = Mockito.mock(RoutingContext.class);
HashSet<Cookie> cookieSet = new HashSet<>();
String cookieValue = "cookieValue";
CookieImpl cookie = new CookieImpl(COOKIE_NAME, cookieValue);
cookieSet.add(cookie);
Mockito.when(mockContext.cookieCount()).thenReturn(1);
Mockito.when(mockContext.cookies()).thenReturn(cookieSet);
param.setContextData(mockContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertEquals(cookieValue, result);
}
use of io.vertx.ext.web.impl.CookieImpl in project vertx-web by vert-x3.
the class CookieHandlerImpl method handle.
@Override
public void handle(RoutingContext context) {
String cookieHeader = context.request().headers().get(COOKIE);
if (cookieHeader != null) {
Set<io.netty.handler.codec.http.cookie.Cookie> nettyCookies = ServerCookieDecoder.STRICT.decode(cookieHeader);
for (io.netty.handler.codec.http.cookie.Cookie cookie : nettyCookies) {
Cookie ourCookie = new CookieImpl(cookie);
context.addCookie(ourCookie);
}
}
context.addHeadersEndHandler(v -> {
// save the cookies
Set<Cookie> cookies = context.cookies();
for (Cookie cookie : cookies) {
if (cookie.isChanged()) {
context.response().headers().add(SET_COOKIE, cookie.encode());
}
}
});
context.next();
}
Aggregations