1
0
mirror of https://github.com/square/okhttp.git synced 2026-10-24 07:59:29 +03:00

136 Commits

Author SHA1 Message Date
Jake Wharton
da5ce5c638 Use BouncyCastle BOM (#9669)
They patch these independently, so just rely on the BOM to figure out what's latest.
2026-08-14 11:56:41 -04:00
Jesse Wilson
071ea23d95 End-to-end test for securely disabling ECH (#9662)
* End-to-end test for securely disabling ECH

* Opt-in to more things

* Track behavior changes in FakeTlsTest

* Fixup getSession exceptions
2026-08-13 23:16:04 -04:00
Jesse Wilson
c4acb20e98 Update EchTest to reflect current behavior (#9658)
Prior to these changes the test fails for me.
2026-08-13 09:32:31 -04:00
Yuri Schimke
bab5c3b2e2 Handle ECH Retry (#9611)
* Handle ECH Retry
* Update tests and retry logic
* Bessify the docs
* Fix the test ports
2026-08-12 19:58:29 +01:00
Jesse Wilson
5e0b9d7198 Fold EchAwareDns into AndroidDns (#9645)
* Fold EchAwareDns into AndroidDns

I don't think each DNS feature should be its own DNS class; instead the single
DNS implementation should be configurable.

None of these classes have shipped in a stable release, so there's no risk
of breaking backwards-compatibility.

* Track changes in EchClientTest
2026-08-10 13:16:11 -04:00
Jesse Wilson
95e097c40a Completely fake out the network for simple tests (#9636)
* Completely fake out the network for simple tests

This covers the happy path of OkHttp + MockWebServer with no
TLS.

There's nothing too exciting here, other than using Okio's
inMemorySocketPair instead of a proper TCP socket for data.

In a follow-up PR I intend to layer on TLS including all the
exotic options like ECH and handshake failures. I won't do
any actual cryptography, just like how this doesn't do any
actual TCP packets.

* Update okhttp-testing-support/src/main/kotlin/okhttp3/sockets/FakeNetwork.kt

Co-authored-by: Yuri Schimke <yuri@schimke.ee>

* Spotless

* Track some API changes in Android tests

---------

Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2026-08-07 10:00:22 -04:00
renovate[bot]
f9263c3615 Update org.bouncycastle (#9603)
* Update org.bouncycastle

* Upgrade and fix issues with BC versions

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2026-07-28 09:36:34 +01:00
Yuri Schimke
e005148cce Add a test with network pinning (#9607)
* Add a test with network pinning

Implicitly tests the ECH code paths, but not ECH servers on API 37.
2026-07-26 23:57:22 +01:00
Yuri Schimke
f04ccb003a Fix failing test on Android 37 dur to conscrypt provider (#9610) 2026-07-26 22:45:59 +01:00
Yuri Schimke
710d6ffbf4 Add proper EchTests (#9604) (#9608)
* Add local only EchTests taken from curl
2026-07-26 15:45:20 +01:00
Yuri Schimke
fb13116f75 Add Android ECH support (#9573)
* Add Android ECH support via DNS state machine

Adds AndroidDns, backed by the system resolver and Android's DnsResolver
for HTTPS/ECH records, driving okhttp's StateMachineDnsCall as a transport.
Adds Android17SocketAdapter for platform ALPN/session-ticket/ECH setup on
API 37+. Pins Robolectric android-test to SDK 36.
2026-07-24 12:20:30 +01:00
Jesse Wilson
7da9284510 Create a place for ECH in our configureTlsExtensions API (#9558)
* Create a place for ECH in our configureTlsExtensions API

* Trailing comma
2026-07-19 09:45:02 -04:00
Pablo Baxter
71b6f9c493 Update all the documentation to prevent broken links everywhere (#9552) 2026-07-16 17:11:28 -04:00
Yuri Schimke
359febc4e2 emulator 37 testing (#9515)
* Set up API 37 emulator matrix in CI

Refactor the android CI job to drive the emulator matrix off an explicit
target/arch include list and add an experimental, non-blocking API 37
(16 KB page-size) entry. Warm the Gradle cache by assembling the
instrumentation APK instead of running the Robolectric unit tests, match
the snapshot boot options on the run step so cached snapshots restore,
and bump emulator memory/GPU/feature flags for headless runs.

Extracted from the testing_ech branch so the emulator setup can land
ahead of the ECH work.

* Fix android-test instrumentation tests for the API 37 emulator

Three environmental differences surface on the API 37 emulator image and
make connectedCheck fail there:

- The GmsCore Conscrypt provider negotiates TLS 1.3 (not 1.2) from API 37
  onward, so assert the version conditionally.
- The dual-stack loopback tries the unbound address first, emitting a
  ConnectStart/ConnectFailed pair before the successful connect; filter
  those pairs out so the event-sequence assertion is stable across single-
  and dual-stack environments.
- Peer verification failures can arrive wrapped (as a cause or suppressed
  exception) rather than thrown directly; accept any of those shapes.

These are independent of the Android 17 platform/ECH work, so they can
land with the emulator CI setup ahead of it.
2026-06-27 20:33:10 +00:00
Yuri Schimke
6b0151aa75 Move androidDeviceTest to androidTest (#9405)
* Move androidDeviceTest to androidTest

Rename the source directory for Android device tests to the standard `androidTest` location.

* skip tests for now on 21, 23
2026-04-05 15:53:43 +01:00
Yuri Schimke
c4f96b781a Adopt a full modern gradle build (#9292)
* Introduce build-logic decoupled convention plugins
* Switch to a full modern gradle build
2026-02-03 22:17:59 +00:00
renovate[bot]
e7c50cce8c Update dependency com.diffplug.spotless:spotless-plugin-gradle to v8.2.0 (#9268)
* Update dependency com.diffplug.spotless:spotless-plugin-gradle to v8.2.0
* spotless cleanup

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2026-01-27 09:00:39 +00:00
Yuri Schimke
1672930a0d Enable AGP newDsl (#9269)
Enable AGP newDsl

- Rename to androidHostTest and include resources
- avoid running robolectric on JDK < 17
- Avoid connectedReleaseAndroidTest for now
2026-01-26 07:38:51 +00:00
Yuri Schimke
d75b142c12 Update to AGP 9 (#9264)
* Update to AGP 9

First milestone with compat workarounds in place.
2026-01-25 15:00:18 +00:00
Jesse Wilson
80b9f556dc Don't run remote tests in CI (#9207)
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-11-21 07:33:41 -05:00
Jesse Wilson
d1aaf7c6cc Split RecordingEventListener in two (#9180)
The first half is EventListenerAdapter, which mechanically
converts event function calls and emits event objects.

The second half is EventRecorder, which validates that the
right events are published.

This is in preparation for a follow-up where I intend
to dynamically add EventListeners to a Call.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-11-04 14:13:52 -05:00
Yuri Schimke
690d1df929 Make tests fail on UnsupportedOperationException (#9135)
* Make tests fail on UnsupportedOperationException

Will fail without the okio fix.

```
09:14:49.703  E  FATAL EXCEPTION: MockWebServer TaskRunner (Ask Gemini)
                 Process: okhttp.android.test.test, PID: 10087
                 java.lang.UnsupportedOperationException
                 	at javax.net.ssl.SSLSocket.shutdownOutput(SSLSocket.java:851)
                 	at okio.internal.DefaultSocket$SocketSink.close(DefaultSocket.kt:95)
                 	at okio.ForwardingSink.close(ForwardingSink.kt:37)
                 	at mockwebserver3.internal.MockWebServerSocket$sink$1.close(MockWebServerSocket.kt:69)
                 	at okio.RealBufferedSink.close(RealBufferedSink.kt:287)
                 	at okhttp3.internal.http2.Http2Writer.close(Http2Writer.kt:331)
                 	at okhttp3.internal.http2.Http2Connection.close$okhttp(Http2Connection.kt:474)
                 	at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:638)
                 	at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:619)
                 	at okhttp3.internal.concurrent.TaskQueue$execute$1.runOnce(TaskQueue.kt:112)
                 	at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:81)
                 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                 	at java.lang.Thread.run(Thread.java:818)
```

* cleanup
2025-10-10 11:26:44 +01:00
Yuri Schimke
d5b3f2c762 Fix SSL Handshake issue affecting MockWebserver on Android 24 (#9129)
* Fix SSL Handshake issue affecting MockWebserver on Android 24

Only called in MWS, but fails on API 24 when called. Adds a single Junit 4 test to run on Android 21-24.

Add a test since Junit 5 wasn't running on older devices.

* fix version number

* reformat

* reformat
2025-10-10 06:19:46 +01:00
Jesse Wilson
81cfb68ac0 Fewer strings in EventListener asserts (#9118)
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-07 14:15:56 -04:00
Yuri Schimke
b7290e4db2 Add multi-release jars to enable Java Modules (#8767)
* Add multi-release jars to enable Java Modules
* Fix android tests
* Avoid running module tests on JDK 8
* Add a jlink run task to demonstrate java modules
2025-09-21 07:22:22 +01:00
Yuri Schimke
bc5ad233f1 Bump robolectric to 4.16 (#9044)
* Bump robolectric

* test with 36

* avoid requiring JDK 21 for Robolectric tests
2025-08-30 17:25:39 +01:00
Benoît Quenaudon
0e0352920b Move the Android test README under the androidTest directory (#9031)
And opt-in to compile without errors
2025-08-22 09:12:58 +01:00
Benoît Quenaudon
929a41c01c Print URLs in HttpLoggingInterceptor when the call fails (#9030) 2025-08-21 15:27:04 +01:00
Yuri Schimke
67c1b8e419 Split android OkHttpClient tests. (#8991)
* Split android OkHttpClient tests.

current tests were using a single client then
testing real network (facebook, ...) and localhost insecure.

Split so we get clearer failures.
2025-08-02 15:12:28 +01:00
Yuri Schimke
3004abe400 okhttp3.Gzip (#8988)
* okhttp3.Gzip

Top level object for consistency.

* reformat and apis
2025-08-01 06:04:22 +00:00
Yuri Schimke
971101cacc Add reusable CompressionInterceptor (#8967)
* Add reusable CompressionInterceptor.kt

Refactor Brotli and Zstd to use this, but also
allow trivial configuration of zstd,br,gzip.
2025-07-29 20:01:04 +00:00
Yuri Schimke
07fe953b40 Add Android OkHttp.initialize(Context) (#8965)
* Add OkHttp.initialiseApplicationContext

A fallback for apps Disabling the AndroidX Startup Initialiser.
2025-07-28 08:33:49 +01:00
Yuri Schimke
50f1be974d Add test demonstrating topPrivateDomain on Robolectric (#8954)
* Add test demonstrating topPrivateDomain on Robolectric
* Handle non robo case
2025-07-22 21:03:31 +01:00
Jesse Wilson
5f3ec584f7 Switch to @StartStop for JUnit 5 tests (#8863)
* New @StartStop extension for JUnit 5

This is a new take on our JUnit 5 extension. Rather than creating and managing
the MockWebServer instance in the extension, we let the user create it and all
the extension does is manage the lifecycle.

Note that this annotation doesn't require any external configuration - it doesn't
need a system-property to opt-into 'automatic' extensions, and it doesn't require
a class-level extension either.

* apiDump

* Switch to @StartStop for JUnit 5 tests

* Fixup visibility

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-18 08:28:21 -04:00
Yuri Schimke
24b8d2942c Add a test and fix for non-robolectric android test. (#8844)
If Robolectric not active, then unit tests for Android will fail annoyingly.
2025-06-07 11:09:33 +01:00
Jesse Wilson
8720aa82ce Temporarily stash the AsyncDns stuff (#8823)
It isn't used anywhere yet. I want to get back to this soon
but I don't want to release 5.0.0 final with any incomplete
APIs.

https://github.com/square/okhttp/issues/8318
2025-05-29 16:09:10 -04:00
Jesse Wilson
7513e02567 Fix a failing test by adding a FollowUpDecision event (#8809)
* Fix a failing test by adding a FollowUpDecision event

* Fix up the other events list

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-05-27 14:52:42 -04:00
Jesse Wilson
0e7ec0bc1c Fix some missing copyright statements (#8789) 2025-05-22 10:39:30 -04:00
Yuri Schimke
f2640e0b08 Create a friends configuration to use internals. (#8651)
* Create a friends configuration to use internals.

From https://www.liutikas.net/2025/01/12/Kotlin-Library-Friends.html we should avoid using

@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")

So instead lets just be friends.
2025-05-10 12:15:14 +01:00
renovate[bot]
a51cfbf841 Update dependency com.diffplug.spotless:spotless-plugin-gradle to v7 (#8702)
* Update dependency com.diffplug.spotless:spotless-plugin-gradle to v7

* Reformat

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jake Wharton <jw@squareup.com>
2025-03-19 15:25:20 -04:00
renovate[bot]
c4d472cab7 Update dependency androidx.activity:activity-ktx to v1.10.1 (#8654)
* Update dependency androidx.activity:activity-ktx to v1.10.1

* compileSdk 35

* Update build.gradle.kts

* compileeeeeeeeeee

* Update build.gradle.kts

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jake Wharton <jw@squareup.com>
2025-03-17 11:11:24 -04:00
Yuri Schimke
9c653c7b0a Add a StrictMode noteSlowCall for SSL init (#8339)
Add strict mode checks on slow calls
2025-01-05 13:15:05 +00:00
Yuri Schimke
dd5a002d44 Use Assets or Resources based on platform. (#8636)
* Use Assets and Resources based on platform.

Assets uncompressed on Android. Assuming that the AAR file will compress.

Use Resources, compressed on JVM.
2024-12-31 16:50:53 +02:00
Yuri Schimke
1786dd70e7 Merge okhttp-android into okhttp (#8635)
* Merge okhttp-android into okhttp.

Since :okhttp is kmp, it isn't required to be separate. And also the okhttp-android/jvm artifact naming conflicts with it.
2024-12-31 01:28:56 +02:00
Yuri Schimke
5163d93806 Spotless bump (#8205)
* Update dependency com.diffplug.spotless:spotless-plugin-gradle to v6.24.0
* Spotless bump

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-20 10:30:28 +00:00
Yuri Schimke
a16dcecfeb Allow constructor injection of MockWebServer (#8191) 2024-01-14 10:20:09 +00:00
Jesse Wilson
a228fd64cc Reformat with Spotless (#8180)
* Enable spotless

* Run spotlessApply

* Fixup trimMargin

* Re-run spotlessApply
2024-01-07 20:13:22 -05:00
Jesse Wilson
ea735b03ff Attempt to fix the android-test build (#8178) 2024-01-06 21:31:24 -05:00
Yuri Schimke
a696d4d333 Fix android test targetSdk (#8158) 2023-12-24 06:39:41 +00:00
Jesse Wilson
c056530682 Switch back to the kotlin JVM plugin (#8149)
* Switch back to the kotlin JVM plugin

This does a ton of file moves from jvmMain to main, and jvmTest to test.

* Don't use AnimalSniffer on okcurl

* Use assertk more (#8150)
2023-12-20 18:27:07 -05:00