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

org.rx.net.http.AuthenticProxy Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.net.http;

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

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

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

    public AuthenticProxy(Type type, SocketAddress sa, String username, String password) {
        super(type, sa);
        authenticator = (route, response) -> {
            String name = HttpHeaders.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