中国网站设计师,建设本地网站 配置iis,1688的网站特色,德勤管理咨询背景 okHttp处理流程 okHttp 代理 为什么没走代理
okhttp选择proxy时#xff0c;现将传入的url传换为uri#xff0c;如果uri的host为空#xff0c;okhttp选择直连url#xff0c;放弃走代理
okhttp3.internal.connection.RouteSelector private fun resetNextProxy(…背景 okHttp处理流程 okHttp 代理 为什么没走代理
okhttp选择proxy时现将传入的url传换为uri如果uri的host为空okhttp选择直连url放弃走代理
okhttp3.internal.connection.RouteSelector private fun resetNextProxy(url: HttpUrl, proxy: Proxy?) {fun selectProxies(): ListProxy {// If the user specifies a proxy, try that and only that.if (proxy ! null) return listOf(proxy)// If the URI lacks a host (as in http:///), dont call the ProxySelector.val uri url.toUri()//此处如果host解析出来为null。放弃走设置的代理if (uri.host null) return immutableListOf(Proxy.NO_PROXY)// Try each of the ProxySelector choices until one connection succeeds.val proxiesOrNull address.proxySelector.select(uri)if (proxiesOrNull.isNullOrEmpty()) return immutableListOf(Proxy.NO_PROXY)return proxiesOrNull.toImmutableList()}eventListener.proxySelectStart(call, url)proxies selectProxies()nextProxyIndex 0eventListener.proxySelectEnd(call, url, proxies)} val uri url.toUri() 函数扒到底实际获取hostName的执行代码如下。java.net.Uri包解uri时如果uri的host不合法则降级设置host为null。
java.net.uri类节选代码 private int parseAuthority(int start, int n)throws URISyntaxException{...if (serverChars) {// Might be (probably is) a server-based authority, so attempt// to parse it as such. If the attempt fails, try to treat it// as a registry-based authority.try {//此处解析hostName不合法的话会扔出URISyntaxException异常q parseServer(p, n);if (q n)failExpecting(end of authority, q);authority substring(p, n);} catch (URISyntaxException x) {// Undo results of failed parseuserInfo null;//host被赋值为空指针host null;port -1;if (requireServerAuthority) {// If were insisting upon a server-based authority,// then just re-throw the exceptionthrow x;} else {// ex x;q p;}}}...return n;}