diff --git a/mockwebserver/src/main/java/okhttp3/mockwebserver/MockWebServer.kt b/mockwebserver/src/main/java/okhttp3/mockwebserver/MockWebServer.kt index f7e4cd509..beeb24fd2 100644 --- a/mockwebserver/src/main/java/okhttp3/mockwebserver/MockWebServer.kt +++ b/mockwebserver/src/main/java/okhttp3/mockwebserver/MockWebServer.kt @@ -1019,7 +1019,7 @@ class MockWebServer : ExternalResource(), Closeable { ) { for (pushPromise in promises) { val pushedHeaders = mutableListOf
() - pushedHeaders.add(Header(Header.TARGET_AUTHORITY, url(pushPromise.path).host())) + pushedHeaders.add(Header(Header.TARGET_AUTHORITY, url(pushPromise.path).host)) pushedHeaders.add(Header(Header.TARGET_METHOD, pushPromise.method)) pushedHeaders.add(Header(Header.TARGET_PATH, pushPromise.path)) val pushPromiseHeaders = pushPromise.headers diff --git a/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt b/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt index 3eb836e10..cd336ca2d 100644 --- a/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt +++ b/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.kt @@ -309,7 +309,7 @@ class DnsOverHttps internal constructor(builder: Builder) : Dns { val hosts = builder.bootstrapDnsHosts return if (hosts != null) { - BootstrapDns(builder.url!!.host(), hosts) + BootstrapDns(builder.url!!.host, hosts) } else { builder.systemDns } diff --git a/okhttp-urlconnection/src/main/java/okhttp3/JavaNetAuthenticator.kt b/okhttp-urlconnection/src/main/java/okhttp3/JavaNetAuthenticator.kt index 90133e3d3..7768483ca 100644 --- a/okhttp-urlconnection/src/main/java/okhttp3/JavaNetAuthenticator.kt +++ b/okhttp-urlconnection/src/main/java/okhttp3/JavaNetAuthenticator.kt @@ -45,21 +45,21 @@ class JavaNetAuthenticator : okhttp3.Authenticator { proxyAddress.hostName, proxy.connectToInetAddress(url), proxyAddress.port, - url.scheme(), + url.scheme, challenge.realm, challenge.scheme, - url.url(), + url.toUrl(), Authenticator.RequestorType.PROXY ) } else { Authenticator.requestPasswordAuthentication( - url.host(), + url.host, proxy.connectToInetAddress(url), - url.port(), - url.scheme(), + url.port, + url.scheme, challenge.realm, challenge.scheme, - url.url(), + url.toUrl(), Authenticator.RequestorType.SERVER ) } @@ -80,7 +80,7 @@ class JavaNetAuthenticator : okhttp3.Authenticator { @Throws(IOException::class) private fun Proxy.connectToInetAddress(url: HttpUrl): InetAddress { return when { - type() == Proxy.Type.DIRECT -> InetAddress.getByName(url.host()) + type() == Proxy.Type.DIRECT -> InetAddress.getByName(url.host) else -> (address() as InetSocketAddress).address } } diff --git a/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt b/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt index 8f50c9c5e..d624e5ad3 100644 --- a/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt +++ b/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.kt @@ -36,7 +36,7 @@ class JavaNetCookieJar(private val cookieHandler: CookieHandler) : CookieJar { } val multimap = mapOf("Set-Cookie" to cookieStrings) try { - cookieHandler.put(url.uri(), multimap) + cookieHandler.put(url.toUri(), multimap) } catch (e: IOException) { Platform.get().log(WARN, "Saving cookies failed for " + url.resolve("/...")!!, e) } @@ -45,7 +45,7 @@ class JavaNetCookieJar(private val cookieHandler: CookieHandler) : CookieJar { override fun loadForRequest(url: HttpUrl): List { val cookieHeaders = try { // The RI passes all headers. We don't have 'em, so we don't pass 'em! - cookieHandler.get(url.uri(), emptyMap>()) + cookieHandler.get(url.toUri(), emptyMap>()) } catch (e: IOException) { Platform.get().log(WARN, "Loading cookies failed for " + url.resolve("/...")!!, e) return emptyList() @@ -102,7 +102,7 @@ class JavaNetCookieJar(private val cookieHandler: CookieHandler) : CookieJar { result.add(Cookie.Builder() .name(name) .value(value) - .domain(url.host()) + .domain(url.host) .build()) pos = pairEnd + 1 } diff --git a/okhttp/src/main/java/okhttp3/Address.kt b/okhttp/src/main/java/okhttp3/Address.kt index 6d021ce82..80313dafd 100644 --- a/okhttp/src/main/java/okhttp3/Address.kt +++ b/okhttp/src/main/java/okhttp3/Address.kt @@ -194,12 +194,12 @@ class Address( this.sslSocketFactory == that.sslSocketFactory && this.hostnameVerifier == that.hostnameVerifier && this.certificatePinner == that.certificatePinner && - this.url.port() == that.url.port() + this.url.port == that.url.port } override fun toString(): String { return "Address{" + - "${url.host()}:${url.port()}, " + + "${url.host}:${url.port}, " + (if (proxy != null) "proxy=$proxy" else "proxySelector=$proxySelector") + "}" } diff --git a/okhttp/src/main/java/okhttp3/CertificatePinner.kt b/okhttp/src/main/java/okhttp3/CertificatePinner.kt index bbb81255f..6d6637bef 100644 --- a/okhttp/src/main/java/okhttp3/CertificatePinner.kt +++ b/okhttp/src/main/java/okhttp3/CertificatePinner.kt @@ -292,10 +292,10 @@ data class CertificatePinner internal constructor( internal fun newPin(pattern: String, pin: String): Pin { val canonicalHostname = when { pattern.startsWith(WILDCARD) -> { - HttpUrl.get("http://${pattern.substring(WILDCARD.length)}").host() + HttpUrl.get("http://${pattern.substring(WILDCARD.length)}").host } else -> { - HttpUrl.get("http://$pattern").host() + HttpUrl.get("http://$pattern").host } } diff --git a/okhttp/src/main/java/okhttp3/Cookie.kt b/okhttp/src/main/java/okhttp3/Cookie.kt index 3815043ff..5f4819cb8 100644 --- a/okhttp/src/main/java/okhttp3/Cookie.kt +++ b/okhttp/src/main/java/okhttp3/Cookie.kt @@ -99,9 +99,9 @@ data class Cookie private constructor( */ fun matches(url: HttpUrl): Boolean { val domainMatch = if (hostOnly) { - url.host() == domain + url.host == domain } else { - domainMatch(url.host(), domain) + domainMatch(url.host, domain) } if (!domainMatch) return false @@ -313,7 +313,7 @@ data class Cookie private constructor( } private fun pathMatch(url: HttpUrl, path: String): Boolean { - val urlPath = url.encodedPath() + val urlPath = url.encodedPath if (urlPath == path) { return true // As in '/foo' matching '/foo'. @@ -426,7 +426,7 @@ data class Cookie private constructor( } // If the domain is present, it must domain match. Otherwise we have a host-only cookie. - val urlHost = url.host() + val urlHost = url.host if (domain == null) { domain = urlHost } else if (!domainMatch(urlHost, domain)) { @@ -442,7 +442,7 @@ data class Cookie private constructor( // If the path is absent or didn't start with '/', use the default path. It's a string like // '/foo/bar' for a URL like 'http://example.com/foo/bar/baz'. It always starts with '/'. if (path == null || !path.startsWith("/")) { - val encodedPath = url.encodedPath() + val encodedPath = url.encodedPath val lastSlash = encodedPath.lastIndexOf('/') path = if (lastSlash != 0) encodedPath.substring(0, lastSlash) else "/" } diff --git a/okhttp/src/main/java/okhttp3/HttpUrl.kt b/okhttp/src/main/java/okhttp3/HttpUrl.kt index 50fa10f6f..fd9b71999 100644 --- a/okhttp/src/main/java/okhttp3/HttpUrl.kt +++ b/okhttp/src/main/java/okhttp3/HttpUrl.kt @@ -738,15 +738,15 @@ class HttpUrl internal constructor( fun newBuilder(): Builder { val result = Builder() result.scheme = scheme - result.encodedUsername = encodedUsername() - result.encodedPassword = encodedPassword() + result.encodedUsername = encodedUsername + result.encodedPassword = encodedPassword result.host = host // If we're set to a default port, unset it in case of a scheme change. result.port = if (port != defaultPort(scheme)) port else -1 result.encodedPathSegments.clear() - result.encodedPathSegments.addAll(encodedPathSegments()) - result.encodedQuery(encodedQuery()) - result.encodedFragment = encodedFragment() + result.encodedPathSegments.addAll(encodedPathSegments) + result.encodedQuery(encodedQuery) + result.encodedFragment = encodedFragment return result } @@ -1365,14 +1365,14 @@ class HttpUrl internal constructor( } } else { // This is a relative link. Copy over all authority components. Also maybe the path & query. - this.encodedUsername = base.encodedUsername() - this.encodedPassword = base.encodedPassword() + this.encodedUsername = base.encodedUsername + this.encodedPassword = base.encodedPassword this.host = base.host this.port = base.port this.encodedPathSegments.clear() - this.encodedPathSegments.addAll(base.encodedPathSegments()) + this.encodedPathSegments.addAll(base.encodedPathSegments) if (pos == limit || input[pos] == '#') { - encodedQuery(base.encodedQuery()) + encodedQuery(base.encodedQuery) } } diff --git a/okhttp/src/main/java/okhttp3/RealCall.kt b/okhttp/src/main/java/okhttp3/RealCall.kt index 639bf7b93..6ae5f6c37 100644 --- a/okhttp/src/main/java/okhttp3/RealCall.kt +++ b/okhttp/src/main/java/okhttp3/RealCall.kt @@ -101,7 +101,7 @@ internal class RealCall private constructor( this.callsPerHost = other.callsPerHost } - fun host(): String = originalRequest.url().host() + fun host(): String = originalRequest.url().host fun request(): Request = originalRequest diff --git a/okhttp/src/main/java/okhttp3/internal/Util.kt b/okhttp/src/main/java/okhttp3/internal/Util.kt index afec1b23b..b4fde36c0 100644 --- a/okhttp/src/main/java/okhttp3/internal/Util.kt +++ b/okhttp/src/main/java/okhttp3/internal/Util.kt @@ -139,13 +139,13 @@ fun nonEmptyIntersection( } fun hostHeader(url: HttpUrl, includeDefaultPort: Boolean): String { - val host = if (":" in url.host()) { - "[${url.host()}]" + val host = if (":" in url.host) { + "[${url.host}]" } else { - url.host() + url.host } - return if (includeDefaultPort || url.port() != HttpUrl.defaultPort(url.scheme())) { - "$host:${url.port()}" + return if (includeDefaultPort || url.port != HttpUrl.defaultPort(url.scheme)) { + "$host:${url.port}" } else { host } @@ -288,9 +288,9 @@ fun toHeaderBlock(headers: Headers): List
= (0 until headers.size).map { } /** Returns true if an HTTP request for [a] and [b] can reuse a connection. */ -fun sameConnection(a: HttpUrl, b: HttpUrl): Boolean = (a.host() == b.host() && - a.port() == b.port() && - a.scheme() == b.scheme()) +fun sameConnection(a: HttpUrl, b: HttpUrl): Boolean = (a.host == b.host && + a.port == b.port && + a.scheme == b.scheme) fun eventListenerFactory(listener: EventListener): EventListener.Factory = EventListener.Factory { listener } diff --git a/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.kt b/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.kt index 93db00b8d..ec6c5a5c5 100644 --- a/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.kt +++ b/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.kt @@ -242,7 +242,7 @@ class CacheStrategy internal constructor( return if (delta > 0L) delta else 0L } - if (lastModified != null && cacheResponse.request().url().query() == null) { + if (lastModified != null && cacheResponse.request().url().query == null) { // As recommended by the HTTP RFC and implemented in Firefox, the max age of a document // should be defaulted to 10% of the document's age at the time it was served. Default // expiration dates aren't used for URIs containing a query. diff --git a/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.kt b/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.kt index 11ede6553..b08b711dd 100644 --- a/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.kt +++ b/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.kt @@ -152,7 +152,7 @@ class RealConnection( throw RouteException(UnknownServiceException( "CLEARTEXT communication not enabled for client")) } - val host = route.address().url.host() + val host = route.address().url.host if (!Platform.get().isCleartextTrafficPermitted(host)) { throw RouteException(UnknownServiceException( "CLEARTEXT communication to $host not permitted by network security policy")) @@ -322,7 +322,7 @@ class RealConnection( val sink = this.sink!! socket.soTimeout = 0 // HTTP/2 connection timeouts are set per-stream. val http2Connection = Http2Connection.Builder(true) - .socket(socket, route.address().url.host(), source, sink) + .socket(socket, route.address().url.host, source, sink) .listener(this) .pingIntervalMillis(pingIntervalMillis) .build() @@ -339,12 +339,12 @@ class RealConnection( try { // Create the wrapper over the connected socket. sslSocket = sslSocketFactory!!.createSocket( - rawSocket, address.url.host(), address.url.port(), true /* autoClose */) as SSLSocket + rawSocket, address.url.host, address.url.port, true /* autoClose */) as SSLSocket // Configure the socket's ciphers, TLS versions, and extensions. val connectionSpec = connectionSpecSelector.configureSecureSocket(sslSocket) if (connectionSpec.supportsTlsExtensions()) { - Platform.get().configureTlsExtensions(sslSocket, address.url.host(), address.protocols) + Platform.get().configureTlsExtensions(sslSocket, address.url.host, address.protocols) } // Force handshake. This can throw! @@ -354,24 +354,24 @@ class RealConnection( val unverifiedHandshake = sslSocketSession.handshake() // Verify that the socket's certificates are acceptable for the target host. - if (!address.hostnameVerifier!!.verify(address.url.host(), sslSocketSession)) { + if (!address.hostnameVerifier!!.verify(address.url.host, sslSocketSession)) { val peerCertificates = unverifiedHandshake.peerCertificates if (peerCertificates.isNotEmpty()) { val cert = peerCertificates[0] as X509Certificate throw SSLPeerUnverifiedException(""" - |Hostname ${address.url.host()} not verified: + |Hostname ${address.url.host} not verified: | certificate: ${CertificatePinner.pin(cert)} | DN: ${cert.subjectDN.name} | subjectAltNames: ${OkHostnameVerifier.allSubjectAltNames(cert)} """.trimMargin()) } else { throw SSLPeerUnverifiedException( - "Hostname ${address.url.host()} not verified (no certificates)") + "Hostname ${address.url.host} not verified (no certificates)") } } // Check that the certificate pinner is satisfied by the certificates presented. - address.certificatePinner!!.check(address.url.host(), + address.certificatePinner!!.check(address.url.host, unverifiedHandshake.peerCertificates) // Success! Save the handshake and the ALPN protocol. @@ -497,7 +497,7 @@ class RealConnection( if (!this.route.address().equalsNonHost(address)) return false // If the host exactly matches, we're done: this connection can carry the address. - if (address.url.host() == this.route().address().url.host()) { + if (address.url.host == this.route().address().url.host) { return true // This connection is a perfect match. } @@ -518,7 +518,7 @@ class RealConnection( // 4. Certificate pinning must match the host. try { - address.certificatePinner!!.check(address.url.host(), handshake()!!.peerCertificates) + address.certificatePinner!!.check(address.url.host, handshake()!!.peerCertificates) } catch (_: SSLPeerUnverifiedException) { return false } @@ -543,17 +543,17 @@ class RealConnection( fun supportsUrl(url: HttpUrl): Boolean { val routeUrl = route.address().url - if (url.port() != routeUrl.port()) { + if (url.port != routeUrl.port) { return false // Port mismatch. } - if (url.host() == routeUrl.host()) { + if (url.host == routeUrl.host) { return true // Host match. The URL is supported. } // We have a host mismatch. But if the certificate matches, we're still good. return handshake != null && OkHostnameVerifier.verify( - url.host(), handshake!!.peerCertificates[0] as X509Certificate) + url.host, handshake!!.peerCertificates[0] as X509Certificate) } @Throws(SocketException::class) @@ -690,7 +690,7 @@ class RealConnection( override fun protocol(): Protocol = protocol!! override fun toString(): String { - return "Connection{${route.address().url.host()}:${route.address().url.port()}," + + return "Connection{${route.address().url.host}:${route.address().url.port}," + " proxy=${route.proxy()}" + " hostAddress=${route.socketAddress()}" + " cipherSuite=${handshake?.cipherSuite ?: "none"}" + diff --git a/okhttp/src/main/java/okhttp3/internal/connection/RealConnectionPool.kt b/okhttp/src/main/java/okhttp3/internal/connection/RealConnectionPool.kt index 3cd15fcbf..3804c12b8 100644 --- a/okhttp/src/main/java/okhttp3/internal/connection/RealConnectionPool.kt +++ b/okhttp/src/main/java/okhttp3/internal/connection/RealConnectionPool.kt @@ -240,7 +240,7 @@ class RealConnectionPool( if (failedRoute.proxy().type() != Proxy.Type.DIRECT) { val address = failedRoute.address() address.proxySelector.connectFailed( - address.url.uri(), failedRoute.proxy().address(), failure) + address.url.toUri(), failedRoute.proxy().address(), failure) } routeDatabase.failed(failedRoute) diff --git a/okhttp/src/main/java/okhttp3/internal/connection/RouteSelector.kt b/okhttp/src/main/java/okhttp3/internal/connection/RouteSelector.kt index 0810e03ec..461a149b2 100644 --- a/okhttp/src/main/java/okhttp3/internal/connection/RouteSelector.kt +++ b/okhttp/src/main/java/okhttp3/internal/connection/RouteSelector.kt @@ -99,7 +99,7 @@ class RouteSelector( listOf(proxy) } else { // Try each of the ProxySelector choices until one connection succeeds. - val proxiesOrNull = address.proxySelector.select(url.uri()) + val proxiesOrNull = address.proxySelector.select(url.toUri()) if (proxiesOrNull != null && proxiesOrNull.isNotEmpty()) { proxiesOrNull.toImmutableList() } else { @@ -117,7 +117,7 @@ class RouteSelector( private fun nextProxy(): Proxy { if (!hasNextProxy()) { throw SocketException( - "No route to ${address.url.host()}; exhausted proxy configurations: $proxies") + "No route to ${address.url.host}; exhausted proxy configurations: $proxies") } val result = proxies[nextProxyIndex++] resetNextInetSocketAddress(result) @@ -134,8 +134,8 @@ class RouteSelector( val socketHost: String val socketPort: Int if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) { - socketHost = address.url.host() - socketPort = address.url.port() + socketHost = address.url.host + socketPort = address.url.port } else { val proxyAddress = proxy.address() require(proxyAddress is InetSocketAddress) { diff --git a/okhttp/src/main/java/okhttp3/internal/connection/Transmitter.kt b/okhttp/src/main/java/okhttp3/internal/connection/Transmitter.kt index 0b2d11d3b..c27de8165 100644 --- a/okhttp/src/main/java/okhttp3/internal/connection/Transmitter.kt +++ b/okhttp/src/main/java/okhttp3/internal/connection/Transmitter.kt @@ -144,7 +144,7 @@ class Transmitter( certificatePinner = client.certificatePinner() } - return Address(url.host(), url.port(), client.dns(), client.socketFactory(), + return Address(url.host, url.port, client.dns(), client.socketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner, client.proxyAuthenticator(), client.proxy(), client.protocols(), client.connectionSpecs(), client.proxySelector()) } diff --git a/okhttp/src/main/java/okhttp3/internal/http/RequestLine.kt b/okhttp/src/main/java/okhttp3/internal/http/RequestLine.kt index 9cb1ca150..305a77101 100644 --- a/okhttp/src/main/java/okhttp3/internal/http/RequestLine.kt +++ b/okhttp/src/main/java/okhttp3/internal/http/RequestLine.kt @@ -55,8 +55,8 @@ object RequestLine { * URL is. Includes the query component if it exists. */ fun requestPath(url: HttpUrl): String { - val path = url.encodedPath() - val query = url.encodedQuery() + val path = url.encodedPath + val query = url.encodedQuery return if (query != null) "$path?$query" else path } } diff --git a/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.kt b/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.kt index fcbaf91ec..3ed910328 100644 --- a/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.kt +++ b/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.kt @@ -278,7 +278,7 @@ class RetryAndFollowUpInterceptor(private val client: OkHttpClient) : Intercepto val url = userResponse.request().url().resolve(location) ?: return null // If configured, don't follow redirects between SSL and non-SSL. - val sameScheme = url.scheme() == userResponse.request().url().scheme() + val sameScheme = url.scheme == userResponse.request().url().scheme if (!sameScheme && !client.followSslRedirects()) return null // Most redirects don't include a request body. diff --git a/okhttp/src/main/java/okhttp3/internal/http2/Http2ExchangeCodec.kt b/okhttp/src/main/java/okhttp3/internal/http2/Http2ExchangeCodec.kt index 33cc109e3..3576e9615 100644 --- a/okhttp/src/main/java/okhttp3/internal/http2/Http2ExchangeCodec.kt +++ b/okhttp/src/main/java/okhttp3/internal/http2/Http2ExchangeCodec.kt @@ -166,7 +166,7 @@ class Http2ExchangeCodec( if (host != null) { result.add(Header(TARGET_AUTHORITY, host)) // Optional. } - result.add(Header(TARGET_SCHEME, request.url().scheme())) + result.add(Header(TARGET_SCHEME, request.url().scheme)) for (i in 0 until headers.size) { // header names must be lowercase.