OkHttp: a Proxy-Authorization header from an interceptor never reaches the CONNECT
programming.dev
OkHttp: a Proxy-Authorization header from an interceptor never reaches the CONNECT
OkHttp says “Failed to authenticate with proxy”, you’ve checked the password three times, and it’s right. Classic. Look at where you add the header. If you set Proxy-Authorization in an interceptor, it works for http:// URLs and silently does nothing for https:// ones. Interceptors never see the CONNECT that opens the tunnel, so the proxy never gets your login. Put it in proxyAuthenticator on the builder instead. Then add one guard, it’s two lines: if the request already has a Proxy-Authorization header, return null. Skip that and a wrong password costs you 21 tunnel attempts, or an endless loop if the proxy keeps the connection open. SOCKS5 is its own weird path. OkHttp hands it to the JDK, so your proxyAuthenticator is never called and the login comes from java.net.Authenticator. That one is JVM-wide, so I’d only answer when the protocol is SOCKS5 and the host and port are your proxy’s. Oh, and if you count on rotation: the default pool reuses one tunnel, so one exit, for up to 5 idle minutes.
0 comments
No comments yet.