package com.usthe.collector.common.http;

import org.apache.http.conn.util.PublicSuffixMatcher;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
import org.apache.http.protocol.HttpContext;

/**
 * IGNORE_REQUEST_COOKIE cookie策略提供者
 * @author tomsun28
 * @date 2021/8/30 22:40
 */
public class IgnoreReqCookieSpecProvider extends DefaultCookieSpecProvider {

    private volatile CookieSpec cookieSpec;

    public IgnoreReqCookieSpecProvider(PublicSuffixMatcher publicSuffixMatcher) {
        super(publicSuffixMatcher);
    }

    @Override
    public CookieSpec create(HttpContext context) {
        if (cookieSpec == null) {
            synchronized (this) {
                if (cookieSpec == null) {
                    this.cookieSpec = new IgnoreReqCookieSpec();
                }
            }
        }
        return this.cookieSpec;
    }
}
