Proxy support
sttp library by default checks for your System proxy properties (docs):
Following settings are checked:
socksProxyHost
andsocksProxyPort
(default: 1080)http.proxyHost
andhttp.proxyPort
(default: 80)https.proxyHost
andhttps.proxyPort
(default: 443)
Settings are loaded in given order and the first existing value is being used.
Otherwise, proxy values can be specified manually when creating a backend:
import sttp.client4._
val backend = DefaultSyncBackend(
options = BackendOptions.httpProxy("some.host", 8080))
basicRequest
.get(uri"...")
.send(backend) // uses the proxy
Or in case your proxy requires authentication (supported by the JVM backends):
import sttp.client4._
BackendOptions.httpProxy("some.host", 8080, "username", "password")
Ignoring and allowing specific hosts
There are two additional settings that can be provided to via BackendOptions
:
nonProxyHosts
: used to define hosts for which request SHOULD NOT be proxiedonlyProxyHosts
: used to define hosts for which request SHOULD be proxied
If only nonProxyHosts
is provided, then some hosts will be skipped when proxying.
If only onlyProxyHosts
is provided, then requests will be proxied only if host matches provided list.
If both nonProxyHosts
and onlyProxyHosts
are provided, then nonProxyHosts
takes precedence.
Both of these options are Nil
by default.
Wildcards
It is possible to use wildcard, but only as either prefix or suffix. E.g. onlyProxyHosts = List("localhost", "*.local", "127.*")