11# HTTP module
22
3- Internal HTTP client for the Split SDK. Not exposed to SDK consumers .
3+ HTTP client for the Split SDK.
44
55## Building an ` HttpClient `
66
7- Use ` HttpClientImpl.Builder ` to create an instance:
7+ ### Minimal
88
99``` java
1010HttpClient client = new HttpClientImpl .Builder ()
1111 .setConnectionTimeout(15_000 )
1212 .setReadTimeout(15_000 )
13- .setTlsUpdater(tlsUpdater) // optional – TlsUpdater SPI
14- .setProxy(httpProxy) // optional – proxy config from :http-domain
15- .setProxyAuthenticator(authenticator) // optional – SplitAuthenticator from :http-domain
16- .setCertificatePinningConfiguration(pinConfig) // optional – cert pins from :http-domain
17- .setDevelopmentSslConfig(devSslConfig) // optional – dev/test SSL overrides
1813 .build();
1914```
2015
16+ ### With ` HttpClientConfiguration ` (preferred)
17+
18+ Bundle all settings into a single config object from ` :http-domain ` :
19+
20+ ``` java
21+ HttpClientConfiguration config = HttpClientConfiguration . builder()
22+ .connectionTimeout(15_000 )
23+ .readTimeout(15_000 )
24+ .proxy(proxy) // optional
25+ .proxyAuthenticator(authenticator) // optional
26+ .certificatePinningConfiguration(pinConfig) // optional
27+ .developmentSslConfig(devSsl) // optional
28+ .build();
29+
30+ HttpClient client = new HttpClientImpl .Builder ()
31+ .setConfiguration(config)
32+ .setTlsUpdater(tlsUpdater) // optional – TlsUpdater
33+ .build();
34+ ```
35+
36+ Individual setter calls on the builder take precedence over the configuration object.
37+
38+ ### Proxy
39+
40+ ``` java
41+ // Basic auth proxy
42+ HttpProxy proxy = HttpProxy . newBuilder(" proxy.example.com" , 8080 )
43+ .basicAuth(" user" , " pass" )
44+ .build();
45+
46+ // mTLS proxy with custom CA
47+ HttpProxy mtlsProxy = HttpProxy . newBuilder(" proxy.example.com" , 8443 )
48+ .proxyCacert(caCertInputStream)
49+ .mtls(clientCertInputStream, clientKeyInputStream)
50+ .build();
51+
52+ // With a credentials provider (e.g. bearer token)
53+ HttpProxy bearerProxy = HttpProxy . newBuilder(" proxy.example.com" , 8080 )
54+ .credentialsProvider(new BearerCredentialsProvider (tokenSupplier))
55+ .build();
56+ ```
57+
58+ ### Certificate pinning
59+
60+ ``` java
61+ CertificatePinningConfiguration pinConfig = CertificatePinningConfiguration . builder()
62+ .addPin(" sdk.split.io" , " sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" )
63+ .addPin(" *.split.io" , certInputStream) // derive pins from a certificate file
64+ .failureListener(failedHost - > {
65+ Log . w(" Split" , " Certificate pinning failed for " + failedHost);
66+ })
67+ .build();
68+ ```
69+
70+ ### Development SSL overrides
71+
72+ For test environments where the server uses a self-signed certificate:
73+
74+ ``` java
75+ DevelopmentSslConfig devSsl = new DevelopmentSslConfig (trustManager, hostnameVerifier);
76+ ```
77+
78+ ### TLS on older devices
79+
80+ Implement the ` TlsUpdater ` SPI and pass it to the builder.
81+ The client calls ` couldBeOld() ` to decide whether to force TLS 1.2 via ` Tls12OnlySocketFactory ` .
82+
83+ ``` java
84+ TlsUpdater tlsUpdater = new LegacyTlsUpdaterAdapter (context); // provided by :main
85+ ```
86+
2187## Making requests
2288
2389``` java
2490// Simple GET
2591HttpRequest req = client. request(uri, HttpMethod . GET );
2692HttpResponse resp = req. execute();
2793
94+ // POST with body
95+ HttpRequest post = client. request(uri, HttpMethod . POST , jsonBody);
96+ HttpResponse resp = post. execute();
97+
2898// POST with body and extra headers
2999HttpRequest post = client. request(uri, HttpMethod . POST , jsonBody, extraHeaders);
30100HttpResponse resp = post. execute();
@@ -42,17 +112,13 @@ client.addHeaders(commonHeaders);
42112
43113// Streaming-specific headers (only applied to streamRequest calls)
44114client. setStreamingHeader(" SplitSDKClientKey" , clientKey);
115+ client. addStreamingHeaders(streamingHeaders);
45116```
46117
47- ## TLS on older devices
48-
49- Implement the ` TlsUpdater ` SPI and pass it to the builder. The client calls ` couldBeOld() ` to decide whether to force TLS 1.2 via ` Tls12OnlySocketFactory ` .
50-
51118## URI building
52119
53120``` java
54- URI uri = new URIBuilder (" https://sdk.split.io/api" )
55- .addPath(" splitChanges" )
121+ URI uri = new URIBuilder (new URI (" https://sdk.split.io/api" ), " splitChanges" )
56122 .addParameter(" since" , " -1" )
57123 .build();
58124```
0 commit comments