Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 90cb61c

Browse files
committed
improved Proxy handling
1 parent 025f387 commit 90cb61c

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

src/main/java/com/sybit/airtable/Airtable.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.apache.commons.beanutils.ConvertUtils;
1515
import org.apache.commons.beanutils.converters.DateConverter;
1616
import org.apache.commons.beanutils.converters.DateTimeConverter;
17+
import org.apache.http.HttpHost;
1718
import org.slf4j.Logger;
1819
import org.slf4j.LoggerFactory;
1920

@@ -98,13 +99,7 @@ public Airtable configure(String apiKey, String endpointUrl) throws AirtableExce
9899
this.apiKey = apiKey;
99100
this.endpointUrl = endpointUrl;
100101

101-
102-
final String httpProxy = System.getenv("http_proxy");
103-
if(httpProxy != null) {
104-
LOG.info("Use Proxy: Environment variable 'http_proxy' found and used: " + httpProxy);
105-
//Unirest.setProxy(HttpHost.create(httpProxy));
106-
}
107-
102+
setProxy(endpointUrl);
108103

109104
// Only one time
110105
Unirest.setObjectMapper(new ObjectMapper() {
@@ -128,6 +123,27 @@ public String writeValue(Object value) {
128123
return this;
129124
}
130125

126+
/**
127+
* Set Proxy environment for Unirest.
128+
*
129+
* Proxy will be ignored for endpointUrls containing <code>localhost</code> or <code>127.0.0.1,/code>
130+
* @param endpointUrl
131+
*/
132+
private void setProxy(String endpointUrl) {
133+
final String httpProxy = System.getenv("http_proxy");
134+
if(httpProxy != null
135+
&& (endpointUrl.contains("127.0.0.1")
136+
|| endpointUrl.contains("localhost"))) {
137+
LOG.info("Use Proxy: ignored for 'localhost' ann '127.0.0.1'");
138+
Unirest.setProxy(null);
139+
} else if(httpProxy != null) {
140+
LOG.info("Use Proxy: Environment variable 'http_proxy' found and used: " + httpProxy);
141+
Unirest.setProxy(HttpHost.create(httpProxy));
142+
} else {
143+
Unirest.setProxy(null);
144+
}
145+
}
146+
131147
/**
132148
* Getting the base by given property <code>AIRTABLE_BASE</code>.
133149
*
@@ -210,5 +226,6 @@ private String getCredentialProperty(String key) {
210226

211227
public void setEndpointUrl(String endpointUrl) {
212228
this.endpointUrl = endpointUrl;
229+
setProxy(endpointUrl);
213230
}
214231
}

0 commit comments

Comments
 (0)