Search in sources :

Example 1 with Cookie

use of io.undertow.server.handlers.Cookie in project spring-framework by spring-projects.

the class UndertowServerHttpRequest method initCookies.

@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
    MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
    for (String name : this.exchange.getRequestCookies().keySet()) {
        Cookie cookie = this.exchange.getRequestCookies().get(name);
        HttpCookie httpCookie = new HttpCookie(name, cookie.getValue());
        cookies.add(name, httpCookie);
    }
    return cookies;
}
Also used : Cookie(io.undertow.server.handlers.Cookie) HttpCookie(org.springframework.http.HttpCookie) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) HttpCookie(org.springframework.http.HttpCookie)

Example 2 with Cookie

use of io.undertow.server.handlers.Cookie in project spring-framework by spring-projects.

the class UndertowServerHttpResponse method applyCookies.

@Override
protected void applyCookies() {
    for (String name : getCookies().keySet()) {
        for (ResponseCookie httpCookie : getCookies().get(name)) {
            Cookie cookie = new CookieImpl(name, httpCookie.getValue());
            if (!httpCookie.getMaxAge().isNegative()) {
                cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());
            }
            httpCookie.getDomain().ifPresent(cookie::setDomain);
            httpCookie.getPath().ifPresent(cookie::setPath);
            cookie.setSecure(httpCookie.isSecure());
            cookie.setHttpOnly(httpCookie.isHttpOnly());
            this.exchange.getResponseCookies().putIfAbsent(name, cookie);
        }
    }
}
Also used : Cookie(io.undertow.server.handlers.Cookie) ResponseCookie(org.springframework.http.ResponseCookie) CookieImpl(io.undertow.server.handlers.CookieImpl) HttpString(io.undertow.util.HttpString) ResponseCookie(org.springframework.http.ResponseCookie)

Example 3 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testRequestCookieDomainPathVersion.

@Test
public void testRequestCookieDomainPathVersion() {
    Map<String, Cookie> cookies = Cookies.parseRequestCookies(1, false, Arrays.asList("CUSTOMER=WILE_E_COYOTE; $Domain=LOONEY_TUNES; $Version=1; $Path=/"));
    Assert.assertFalse(cookies.containsKey("$Domain"));
    Assert.assertFalse(cookies.containsKey("$Version"));
    Assert.assertFalse(cookies.containsKey("$Path"));
    Cookie cookie = cookies.get("CUSTOMER");
    Assert.assertEquals("CUSTOMER", cookie.getName());
    Assert.assertEquals("WILE_E_COYOTE", cookie.getValue());
    Assert.assertEquals("LOONEY_TUNES", cookie.getDomain());
    Assert.assertEquals(1, cookie.getVersion());
    Assert.assertEquals("/", cookie.getPath());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 4 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testEqualsInValueAllowed.

@Test
public void testEqualsInValueAllowed() {
    Map<String, Cookie> cookies = Cookies.parseRequestCookies(1, true, Arrays.asList("CUSTOMER=WILE_E_COYOTE=THE_COYOTE"));
    Cookie cookie = cookies.get("CUSTOMER");
    Assert.assertNotNull(cookie);
    Assert.assertEquals("WILE_E_COYOTE=THE_COYOTE", cookie.getValue());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 5 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testEqualsInValueAllowedInQuotedValue.

@Test
public void testEqualsInValueAllowedInQuotedValue() {
    Map<String, Cookie> cookies = Cookies.parseRequestCookies(2, true, Arrays.asList("CUSTOMER=\"WILE_E_COYOTE=THE_COYOTE\"; SHIPPING=FEDEX"));
    Assert.assertEquals(2, cookies.size());
    Cookie cookie = cookies.get("CUSTOMER");
    Assert.assertNotNull(cookie);
    Assert.assertEquals("WILE_E_COYOTE=THE_COYOTE", cookie.getValue());
    cookie = cookies.get("SHIPPING");
    Assert.assertNotNull(cookie);
    Assert.assertEquals("FEDEX", cookie.getValue());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Aggregations

Cookie (io.undertow.server.handlers.Cookie)21 UnitTest (io.undertow.testutils.category.UnitTest)12 Test (org.junit.Test)12 CookieImpl (io.undertow.server.handlers.CookieImpl)4 HttpString (io.undertow.util.HttpString)2 NotificationReceiver (io.undertow.security.api.NotificationReceiver)1 SecurityNotification (io.undertow.security.api.SecurityNotification)1 Account (io.undertow.security.idm.Account)1 Session (io.undertow.server.session.Session)1 HeaderMap (io.undertow.util.HeaderMap)1 HeaderValues (io.undertow.util.HeaderValues)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 HttpCookie (org.springframework.http.HttpCookie)1 ResponseCookie (org.springframework.http.ResponseCookie)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1