Comments (22)
Apache http client can support HTTPS proxy:
HttpHost proxy = new HttpHost("https","www.xxx.xxx",8888);
CloseableHttpClient client = HttpClients.custom()
.setProxy(proxy)
.build();
So can OKHTTP client support it also?
from okhttp.
I think we should support. I've set up tests to validate against other proxily servers but haven't been able to easily verify Https behaviour.
Do you have a public test server I can test against? That you know is working ?
from okhttp.
I think we should support. I've set up tests to validate against other proxily servers but haven't been able to easily verify Https behaviour.
Do you have a public test server I can test against? That you know is working ?
Thanks so much for your reply. I donβt currently have a publicly available proxy for you to test; however this is the project we are working from to set up our proxy. I hope this is somewhat helpful.
from okhttp.
I confirmed with smokescreen that this clumsy workaround works
val serverCert = """
-----BEGIN CERTIFICATE-----
MIIE+DCCAuCgAwIBAgIBBTANBgkqhkiG9w0BAQsFADBrMQswCQYDVQQGEwJVUzET
...
B5Ird7f+U0bSPpszX4PMGbydhsuhnbqDamrT0Q==
-----END CERTIFICATE-----
""".trimIndent().decodeCertificatePem()
val certs = HandshakeCertificates.Builder()
.addPlatformTrustedCertificates()
.addTrustedCertificate(serverCert)
.build()
val sslSocketFactory = certs.sslSocketFactory()
val client = OkHttpClient.Builder()
.proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", 4750)))
.socketFactory(sslSocketFactory)
.build()
from okhttp.
OK change in code is simple, except our dependence on java.net.Proxy is limiting.
@swankjesse would it make sense to have our own model for Proxy?
from okhttp.
A quick exploration, I'll revert some of this and see if it looks ok
from okhttp.
Hi @yschimke @swankjesse, Do we have release date for this feature?
from okhttp.
I don't think clean support will make 5.0, as it would require a new Proxy domain model.
Instead I'm aiming to allow this workaround #8379
from okhttp.
@yschimke Do you mean we can have a workaround method without changing the source code?
from okhttp.
@itning No, would require changing the client.
How are you configuring this proxy? Maybe I can see if there is a way to make that path work.
from okhttp.
We don't currently have a similar API to Apache
HttpHost proxy = new HttpHost("https","www.xxx.xxx",8888);
from okhttp.
How are you configuring this proxy? Maybe I can see if there is a way to make that path work.
For now we use apache http client like this: #8373 (comment)
from okhttp.
This would require this clumsy workaround for OkHttp
Or at minimum
// create a ssl socket factory somehow
val sslSocketFactory = OkHttpClient().sslSocketFactory
val client = OkHttpClient.Builder()
.proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", 4750)))
.socketFactory(sslSocketFactory)
.build()
from okhttp.
// create a ssl socket factory somehow
val sslSocketFactory = OkHttpClient().sslSocketFactoryval client = OkHttpClient.Builder() .proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", 4750))) .socketFactory(sslSocketFactory) .build()
I use the code, but got error:
Exception in thread "main" java.lang.IllegalArgumentException: socketFactory instanceof SSLSocketFactory
at okhttp3.OkHttpClient$Builder.socketFactory(OkHttpClient.kt:723)
at xxx.main(xxx.java:178)
from okhttp.
Sorry, I should have been clearer.
It requires this PR, unless you wrap that socket factory again.
from okhttp.
@yschimke I'm sorry to bother you again and request when I can use the solution you provided?
from okhttp.
For now, try something like this
val client =
OkHttpClient.Builder()
.sslSocketFactory(socketFactory, trustManager)
.proxy(Proxy(Proxy.Type.HTTP, it.remoteAddress()))
.protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1))
.socketFactory(socketFactory.asSocketFactory())
.build()
private fun SSLSocketFactory.asSocketFactory(): SocketFactory {
return DelegatingSocketFactory(this)
}
DelegatingSocketFactory would be something like
from okhttp.
Related Issues (20)
- The request body data added in the NetworkInterceptor was found not included in the capture by Charles. HOT 1
- The request body data added in the NetworkInterceptor was found not included in the capture by Charles
- Gzip/Deflate/Bortli not workin okhttp3 4.12.0/5.0.0-alpha12 HOT 5
- DiskLruCache entry?.currentEditor is allways not null for async requests HOT 1
- Documentation: Clearly state that OkHttpClient should be a singleton HOT 6
- downloading big file midway Report an error java.net.ProtocolException: unexpected end of stream HOT 1
- Investigate Lock vs Synchronized performance HOT 4
- okhttp-coroutines in alpha 13 contains core classes HOT 1
- okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL HOT 1
- Cannot instantiate MockWebServer on alpha 14β: java.lang.NoClassDefFoundError: okhttp3/internal/_UtilJvmKt HOT 3
- Failing while building okhttp version parent-3.6.0 using mvn clean install HOT 1
- QUERY support
- No callbacks: no successful callbacks and no failed callbacks HOT 4
- TaskRunner's concurrent performance exhibits a significant decline in case of poor networks conditions HOT 19
- Calling response.body.string() on a MockWebServer response throws a SocketTimeoutException HOT 5
- java.net.SocketException: socket is closed HOT 11
- UTF-32LE and UTF-32BE BOM are incorrect
- Huffman : Fatal Exception: java.lang.NullPointerException HOT 3
- Delayed sending request HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okhttp.