2
2
3
3
import okhttp3 .OkHttpClient ;
4
4
import okhttp3 .logging .HttpLoggingInterceptor ;
5
+ import org .slf4j .Logger ;
6
+ import org .slf4j .LoggerFactory ;
5
7
6
8
import java .util .ArrayList ;
7
9
import java .util .Collections ;
8
10
import java .util .List ;
9
11
import java .util .concurrent .TimeUnit ;
10
12
11
13
public class Config {
14
+ private static final Logger LOG = LoggerFactory .getLogger (Config .class );
12
15
private final String clientId ;
13
16
private final String secret ;
14
17
private final List <Scope > scopes ;
@@ -27,7 +30,7 @@ public Config(String clientId,
27
30
this .clientId = clientId ;
28
31
this .secret = secret ;
29
32
this .scopes = Collections .unmodifiableList (scopes );
30
- this .apiHost = apiHost ;
33
+ this .apiHost = stripPrefix ( apiHost ) ;
31
34
this .useHttps = useHttps ;
32
35
33
36
if (httpLoggingLevel == null ) {
@@ -50,6 +53,20 @@ public Config(String clientId,
50
53
51
54
}
52
55
56
+ // Visible for testing.
57
+ String stripPrefix (String apiHost ) {
58
+ String httpPrefix = "http://" ;
59
+ String httpsPrefix = "https://" ;
60
+ if (apiHost .toLowerCase ().startsWith (httpPrefix )) {
61
+ LOG .warn ("Ignoring http hpiHost scheme, set 'useHttps' to false for http" );
62
+ return apiHost .substring (httpPrefix .length ());
63
+ } else if (apiHost .toLowerCase ().startsWith (httpsPrefix )) {
64
+ return apiHost .substring (httpsPrefix .length ());
65
+ } else {
66
+ return apiHost ;
67
+ }
68
+ }
69
+
53
70
public String getClientId () {
54
71
return clientId ;
55
72
}
0 commit comments