use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class ManagementAPI method buildNetworkingClient.
/**
* Given a set of options, it creates a new instance of the {@link OkHttpClient}
* configuring them according to their availability.
*
* @param options the options to set to the client.
* @return a new networking client instance configured as requested.
*/
private OkHttpClient buildNetworkingClient(HttpOptions options) {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
final ProxyOptions proxyOptions = options.getProxyOptions();
if (proxyOptions != null) {
// Set proxy
clientBuilder.proxy(proxyOptions.getProxy());
// Set authentication, if present
final String proxyAuth = proxyOptions.getBasicAuthentication();
if (proxyAuth != null) {
clientBuilder.proxyAuthenticator(new Authenticator() {
private static final String PROXY_AUTHORIZATION_HEADER = "Proxy-Authorization";
@Override
public okhttp3.Request authenticate(Route route, Response response) throws IOException {
if (response.request().header(PROXY_AUTHORIZATION_HEADER) != null) {
return null;
}
return response.request().newBuilder().header(PROXY_AUTHORIZATION_HEADER, proxyAuth).build();
}
});
}
}
configureLogging(options.getLoggingOptions());
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequestsPerHost(options.getMaxRequestsPerHost());
dispatcher.setMaxRequests(options.getMaxRequests());
return clientBuilder.addInterceptor(logging).addInterceptor(telemetry).addInterceptor(new RateLimitInterceptor(options.getManagementAPIMaxRetries())).connectTimeout(options.getConnectTimeout(), TimeUnit.SECONDS).readTimeout(options.getReadTimeout(), TimeUnit.SECONDS).dispatcher(dispatcher).build();
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class ManagementAPITest method shouldConfigureBodyLoggingFromOptions.
@Test
public void shouldConfigureBodyLoggingFromOptions() {
LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.BODY);
Set<String> headersToRedact = new HashSet<>();
headersToRedact.add("Authorization");
headersToRedact.add("Cookie");
loggingOptions.setHeadersToRedact(headersToRedact);
HttpOptions options = new HttpOptions();
options.setLoggingOptions(loggingOptions);
ManagementAPI api = new ManagementAPI(DOMAIN, API_TOKEN, options);
assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
for (Interceptor i : api.getClient().interceptors()) {
if (i instanceof HttpLoggingInterceptor) {
HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
assertThat(logging.getLevel(), is(Level.BODY));
}
}
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class ManagementAPITest method shouldConfigureNoneLoggingFromOptions.
@Test
public void shouldConfigureNoneLoggingFromOptions() {
LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.NONE);
HttpOptions options = new HttpOptions();
options.setLoggingOptions(loggingOptions);
ManagementAPI api = new ManagementAPI(DOMAIN, API_TOKEN, options);
assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
for (Interceptor i : api.getClient().interceptors()) {
if (i instanceof HttpLoggingInterceptor) {
HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
assertThat(logging.getLevel(), is(Level.NONE));
}
}
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class ManagementAPITest method shouldThrowOnInValidMaxRequestsPerHostConfiguration.
@Test
public void shouldThrowOnInValidMaxRequestsPerHostConfiguration() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("maxRequestsPerHost must be one or greater.");
HttpOptions options = new HttpOptions();
options.setMaxRequestsPerHost(0);
}
use of com.auth0.client.HttpOptions in project auth0-java by auth0.
the class ManagementAPITest method shouldThrowOnInValidMaxRequestsConfiguration.
@Test
public void shouldThrowOnInValidMaxRequestsConfiguration() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("maxRequests must be one or greater.");
HttpOptions options = new HttpOptions();
options.setMaxRequests(0);
}
Aggregations