okhttp v4.7.0 Release Notes

Release Date: 2020-05-17 // almost 4 years ago
  • 2020-05-17

    • New: HandshakeCertificates.Builder.addInsecureHost() makes it easy to turn off security in private development environments that only carry test data. Prefer this over creating an all-trusting TrustManager because only hosts on the allowlist are insecure. From [our DevServer sample][dev_server]:

      val clientCertificates = HandshakeCertificates.Builder()
          .addPlatformTrustedCertificates()
          .addInsecureHost("localhost")
          .build()
      
      val client = OkHttpClient.Builder()
          .sslSocketFactory(clientCertificates.sslSocketFactory(), clientCertificates.trustManager)
          .build()
      
    • New: Add cacheHit, cacheMiss, and cacheConditionalHit() events to EventListener. Use these in logs, metrics, and even test cases to confirm your cache headers are configured as expected.

    • New: Constant string okhttp3.VERSION. This is a string like "4.5.0-RC1", "4.5.0", or "4.6.0-SNAPSHOT" indicating the version of OkHttp in the current runtime. Use this to include the OkHttp version in custom User-Agent headers.

    • Fix: Don't crash when running as a plugin in Android Studio Canary 4.1. To enable platform-specific TLS features OkHttp must detect whether it's running in a JVM or in Android. The upcoming Android Studio runs in a JVM but has classes from Android and that confused OkHttp!

    • Fix: Include the header Accept: text/event-stream for SSE calls. This header is not added if the request already contains an Accept header.

    • Fix: Don't crash with a NullPointerException if a server sends a close while we're sending a ping. OkHttp had a race condition bug.