Permalink
Browse files

Refactor addHeaders() allowing customized headers.

  • Loading branch information...
mawp
mawp committed Oct 23, 2017
1 parent 66019e8 commit d04582ea4ef1d87febd03b367562d9687667ba50
@@ -39,6 +39,8 @@
private final String url;
private final boolean includeRawResponse;
private HashMap<String, String> headersMap = new HashMap<>();
public HttpService(String url, OkHttpClient httpClient, boolean includeRawResponses) {
super(includeRawResponses);
@@ -145,10 +147,14 @@ private InputStream buildInputStream(ResponseBody responseBody) throws IOExcepti
}
private Headers buildHeaders() {
Map<String, String> headers = new HashMap<>();
addHeaders(headers);
return Headers.of(headers);
return Headers.of(headersMap);
}
public void addHeader(String key, String value) {
headersMap.put(key, value);
}
public void addHeaders(Map<String, String> headers) {
headersMap.putAll(headers);
}
protected void addHeaders(Map<String, String> headers) { }
}
@@ -18,6 +18,7 @@
public InfuraHttpService(String url, String clientVersion, boolean required) {
super(url);
clientVersionHeader = buildClientVersionHeader(clientVersion, required);
addHeaders(clientVersionHeader);
}
public InfuraHttpService(String url, String clientVersion) {
@@ -28,11 +29,6 @@ public InfuraHttpService(String url) {
this(url, "", false);
}
@Override
protected void addHeaders(Map<String, String> headers) {
headers.putAll(clientVersionHeader);
}
static Map<String, String> buildClientVersionHeader(String clientVersion, boolean required) {
if (clientVersion == null || clientVersion.equals("")) {
return Collections.emptyMap();

0 comments on commit d04582e

Please sign in to comment.