com.tukeof.common.rest.okhttp.CookieJarImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-rest Show documentation
Show all versions of common-rest Show documentation
a encapsulated restful java library
The newest version!
package com.tukeof.common.rest.okhttp;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Slf4j
public class CookieJarImpl implements CookieJar {
private final HashMap> cookieStore = new HashMap<>();
private final List emptyCookies = new ArrayList<>();
@Override
public void saveFromResponse(HttpUrl url, List cookies) {
cookieStore.put(url.host(), cookies);
}
@Override
public List loadForRequest(HttpUrl url) {
List cookies = cookieStore.get(url.host());
if (cookies != null) {
return cookies;
} else {
return emptyCookies;
}
}
}