All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tukeof.common.rest.okhttp.CookieJarImpl Maven / Gradle / Ivy

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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy