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

org.rx.socks.http.ProxyWithAuth Maven / Gradle / Ivy

package org.rx.socks.http;

import lombok.Getter;
import lombok.Setter;
import okhttp3.*;

import java.net.Proxy;
import java.net.SocketAddress;

public class ProxyWithAuth extends Proxy {
    @Getter
    private Authenticator authenticator;
    @Getter
    @Setter
    private boolean directOnFail;

    public ProxyWithAuth(Type type, SocketAddress sa, String username, String password) {
        super(type, sa);
        authenticator = (route, response) -> {
            String name = "Proxy-Authorization";
            if (directOnFail && response.request().header(name) != null) {
                return null;
            }
            String credential = Credentials.basic(username, password);
            return response.request().newBuilder()
                    .header(name, credential)
                    .build();
        };
        directOnFail = true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy