public Consumer < HttpClientBuilder > createHttpClientCustomiser ( final boolean fastFail , final AuthScope authScope , final Credentials credentials , final boolean preemptiveAuth , final boolean storeCookies , Consumer < HttpClientBuilder > customiser ) { // Customise timeouts if fast fail mode is enabled if ( fastFail ) { customiser = concat ( customiser , b -> { RequestConfig . Builder requestBuilder = RequestConfig . custom ( ) ; requestBuilder . setConnectTimeout ( ( int ) fastFailConnectionTimeout . getMilliseconds ( ) ) . setSocketTimeout ( ( int ) fastFailSocketTimeout . getMilliseconds ( ) ) ; b . setDefaultRequestConfig ( requestBuilder . build ( ) ) ; } ) ; } // If credentials were supplied then we should set them up if ( credentials != null ) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider ( ) ; if ( authScope != null ) credentialsProvider . setCredentials ( authScope , credentials ) ; else credentialsProvider . setCredentials ( AuthScope . ANY , credentials ) ; // Set up bearer auth scheme provider if we're using bearer credentials if ( credentials instanceof BearerCredentials ) { customiser = concat ( customiser , b -> { Registry < AuthSchemeProvider > authSchemeRegistry = RegistryBuilder . < AuthSchemeProvider > create ( ) . register ( "Bearer" , new BearerAuthSchemeProvider ( ) ) . build ( ) ; b . setDefaultAuthSchemeRegistry ( authSchemeRegistry ) ; } ) ; } // Set up the credentials customisation customiser = concat ( customiser , b -> b . setDefaultCredentialsProvider ( credentialsProvider ) ) ; if ( preemptiveAuth && credentials instanceof BearerCredentials ) customiser = concat ( customiser , b -> b . addInterceptorFirst ( new PreemptiveBearerAuthInterceptor ( ) ) ) ; else customiser = concat ( customiser , b -> b . addInterceptorLast ( new PreemptiveBasicAuthInterceptor ( ) ) ) ; } // If cookies are enabled then set up a cookie store if ( storeCookies ) customiser = concat ( customiser , b -> b . setDefaultCookieStore ( new BasicCookieStore ( ) ) ) ; return customiser ; }
N . B . This method signature may change in the future to add new parameters