use of cn.taketoday.http.HttpCookie in project today-infrastructure by TAKETODAY.
the class ReactorServerHttpRequest method initCookies.
@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
DefaultMultiValueMap<String, HttpCookie> cookies = MultiValueMap.fromLinkedHashMap();
for (Map.Entry<CharSequence, Set<Cookie>> entry : request.cookies().entrySet()) {
CharSequence name = entry.getKey();
for (Cookie cookie : entry.getValue()) {
HttpCookie httpCookie = new HttpCookie(name.toString(), cookie.value());
cookies.add(name.toString(), httpCookie);
}
}
return cookies;
}
use of cn.taketoday.http.HttpCookie in project today-infrastructure by TAKETODAY.
the class ServletServerHttpRequest method initCookies.
@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
MultiValueMap<String, HttpCookie> httpCookies = MultiValueMap.fromLinkedHashMap();
Cookie[] cookies;
synchronized (this.cookieLock) {
cookies = this.request.getCookies();
}
if (cookies != null) {
for (Cookie cookie : cookies) {
String name = cookie.getName();
HttpCookie httpCookie = new HttpCookie(name, cookie.getValue());
httpCookies.add(name, httpCookie);
}
}
return httpCookies;
}
use of cn.taketoday.http.HttpCookie in project today-infrastructure by TAKETODAY.
the class CookieSessionIdResolver method retrieveId.
@Override
public String retrieveId(RequestContext context) {
final String cookieName = this.cookieName;
final HttpCookie cookie = context.getCookie(cookieName);
if (cookie == null) {
final ArrayList<HttpCookie> httpCookies = context.responseCookies();
for (final HttpCookie httpCookie : httpCookies) {
if (cookieName.equals(httpCookie.getName())) {
return httpCookie.getValue();
}
}
return null;
}
return cookie.getValue();
}
use of cn.taketoday.http.HttpCookie in project today-infrastructure by TAKETODAY.
the class HttpComponentsClientHttpRequest method applyCookies.
@Override
protected void applyCookies() {
if (getCookies().isEmpty()) {
return;
}
CookieStore cookieStore = this.context.getCookieStore();
for (Map.Entry<String, List<HttpCookie>> entry : getCookies().entrySet()) {
for (HttpCookie cookie : entry.getValue()) {
BasicClientCookie clientCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
clientCookie.setDomain(getURI().getHost());
clientCookie.setPath(getURI().getPath());
cookieStore.addCookie(clientCookie);
}
}
}
use of cn.taketoday.http.HttpCookie in project today-infrastructure by TAKETODAY.
the class DefaultWebSessionManagerTests method testWebSession.
@Test
public void testWebSession() {
try (StandardApplicationContext applicationContext = new StandardApplicationContext()) {
applicationContext.register(AppConfig.class);
applicationContext.refresh();
SessionManager sessionManager = applicationContext.getBean(SessionManager.class);
MockRequestContext context = new MockRequestContext();
WebSession noneExistingSession = sessionManager.getSession(context, false);
assertThat(noneExistingSession).isNull();
WebSession createdSession = sessionManager.getSession(context);
assertThat(createdSession).isNotNull();
// CookieTokenResolver
CookieSessionIdResolver cookieTokenResolver = applicationContext.getBean(CookieSessionIdResolver.class);
List<HttpCookie> responseCookies = context.responseCookies();
String sessionId = createdSession.getId();
HttpCookie sessionCookie = cookieTokenResolver.createCookie(sessionId);
assertThat(responseCookies).hasSize(1);
assertThat(responseCookies.get(0)).isEqualTo(sessionCookie);
// WebSessionStorage
SessionRepository sessionStorage = applicationContext.getBean(SessionRepository.class);
WebSession webSession = sessionStorage.retrieveSession(sessionId);
assertThat(webSession).isEqualTo(createdSession);
assertThat(sessionStorage.contains(sessionId)).isTrue();
sessionStorage.removeSession(sessionId);
assertThat(sessionStorage.contains(sessionId)).isFalse();
}
}
Aggregations