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

262 Commits

Author SHA1 Message Date
Jesse Wilson
a2cf5aa9f8 Don't recover after an ECH public_name fails to verify (#9680)
* Don't recover after an ECH public_name fails to verify

* Fixup a test
2026-08-14 19:44:20 -04:00
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
bb61c63a32 Retry at most once when ECH fails (#9664)
* Retry at most once when ECH fails

Also write some new ECH retry tests.

Also enforce restrictions on public_name structure.

Also rename EchRetryConfig to EchRetryPlan.

* Track behavior change
2026-08-14 10:31:30 -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
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
a4a1c5d631 Get the FakeNetwork via OkHttp's existing Platform thing (#9654)
* Get the FakeNetwork via OkHttp's existing Platform thing

* Don't use an API not in Java 8
2026-08-12 09:43:59 -04: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
a82269bc85 Completely fake out TLS for testing (#9640)
* Completely fake out TLS for testing

This covers the happy path of OkHttp + MockWebServer with HTTPS.

This doesn't actually perform anything cryptographic; certificates
and protocols and things are transmitted in-memory rather than
over the wire.

This replaces the Okio.inMemorySocketPair() after the fake
TLS handshake; that way there's no risk of data leaking from
the pre-encrypted session to the post-encrypted session.

The useful capability this unlocks is testing TLS scenarios
like ECH retries, before we have a server-side TLS stack that
can support them.

* Important documentation

* Tests for the new APIs

* Make cancelation more robust

* Spotless
2026-08-08 22:22:16 -04:00
Jesse Wilson
d1e57f3520 Add overdue tests for FakeNetwork (#9638)
* Add overdue tests for FakeNetwork

The test that uses real OkHttp is good to confirm it works, but it
isn't useful for debugging problems with FakeNetwork.

* Fix flakiness with socket closing
2026-08-07 20:46:04 -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
Jesse Wilson
1682d9bac8 Rearrange new DNS classes without changing behavior (#9584)
* Rearrange new DNS classes without changing behavior

Transport is now DnsQuery.Factory
CachingTransport is now DnsCache
StateMachineDnsCall.Query is now DnsQuery

This is intended to make it possible to have end-users get a DnsCache
instance without being exposed to the implementation details of our
transports and things.

* Use has-a, not is-a for the MemoryCache

* Update AndroidDns

* Track a test API change

* spotless
2026-07-24 12:36:54 -04:00
Jesse Wilson
0f4e198d5f New CachingTransport (#9579)
* Switch to Question as the Transport argument

It makes caching easier.

* New CachingTransport

* spotless

* Switch to ComparableTimeSource

* Switch from computeIfAbsent to putIfAbsent

The former isn't available on API 21.
2026-07-23 11:28:14 -04:00
Jesse Wilson
9b25cc3312 Add a tester just for the DnsCallStateMachine (#9578)
* Add a tester just for the DnsCallStateMachine

A very nice perk of extracting it out so it could be reused for Android,
is that it's also a lot easier to test.

* Spotless
2026-07-23 07:47:11 -04:00
Jesse Wilson
06bd0ef676 Move the DNS call state machine into okhttp (#9576)
* Move the DNS call state machine into okhttp

* Missing annotation
2026-07-22 10:09:24 -04:00
Yuri Schimke
1a3ae1ff29 Move DnsMessage to okhttp core internal (#9571) 2026-07-21 16:47:28 -04:00
Jesse Wilson
6268afe895 Serialize calls to Dns.Callback (#9561)
We had a bug where these calls could be made in parallel. Making
them serial is a bit awkward but doesn't require any locks if we're
clever.
2026-07-19 09:01:41 -04:00
Jesse Wilson
20fcded4b5 Start including ECH data in RouteSelector results (#9557)
* Start including ECH data in RouteSelector results

This changes RouteSelector to use our new async API, when it is
available.

* Extract the execute() function

* Fixup Https results to use targetName

* Fixup some tests

* Use LinkedBlockingQueue instead of CompletableFuture

CompletableFuture isn't available until Android API 24
2026-07-17 19:08:33 -04:00
Jesse Wilson
759a4e5b2d Add ECH service metadata to Route. (#9556)
* Add ECH service metadata to Route.

Also combine DnsOverHttpsServer with FakeDns, so we can serve metadata
anywhere we're testing DNS.

Also move stuff to the 'internal' package in okhttp-dnsoverhttps, so we
can make symbols visible to the main okhttp module's tests.

* Fixup tests

* Test DNS returning zero results
2026-07-17 16:19:48 -04:00
Jesse Wilson
6d0e76d0b9 Define only one DNS interface (#9554) 2026-07-17 11:42:20 -04:00
Yuri Schimke
bdb4ad28a9 Avoid FakeDns flakes (#9305) 2026-02-04 20:20:29 +00: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
7c4b35ba27 Allow OkHttpClient overrides in Interceptor (#9108)
Allow OkHttpClient overrides in Interceptor, generally anything settable on OkHttpClient.Builder can be overridden in application interceptor.

Tests that the effect of overrides takes effect and can be reversed.
2026-01-11 12:06:21 +00:00
Jesse Wilson
e6b7eeee4b Call.addEventListener (#9181)
* Call.addEventListener

Use this to install listeners after-the-fact, such as
in Interceptors or other EventListeners.

* apiDump

* Make eventListener updates atomic

* Fix
2025-11-05 13:28:35 -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
Jesse Wilson
9674bf0d06 Run all the tests in CI (#9178)
* Run all the tests in CI

We haven't been. I would have expected ./gradlew test
to run everything, but it doesn't. We need to explicitly
run jvmTest to get all of our tests to run.

* Use allTests, not jvmTest

* Support Corretto on osx-aarch_64

* Handle the exception message from OpenJDK 21

* Fixup Loom tests

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-11-04 13:33:48 -05:00
Jesse Wilson
0470853d72 Add tags to calls, including computable tags (#9168)
Originally I was planning on implementing tags on
Request only, but that design broke as soon as any
interceptor used Request.newBuilder() to create a
copy of the Request - the instance that received the
tags might not be the instance that needed them.

Instead I'm introducing this behavior on the Call
object, which behaves less like a value. I expect
that users' expected lifetimes of tags will work
naturally this way.

It is an API hazard that we have tags on both
Requests and Calls. Perhaps if given the opportunity
to do it over, I'd omit support for tags on Requests.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-26 10:54:46 -04:00
Jesse Wilson
0030b10a0b Flatten ConnectionUser (#9122)
There's only one implementation in use, and so I'm
inlining it to call through what it ultimately does.

My motivation is to avoid retaining a reference to an
EventListener anywhere, because that value is going
from immutable to mutable.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-07 23:50:05 -04:00
Jesse Wilson
b82f7abf0a Tear down AddressPolicy (#9120)
It's currently unused.

I'd like to bring this feature back soon, but using
regular Calls to make it happen rather than having
Connections created without a Call object. That should
avoid some special cases.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-07 17:55:03 -04:00
Jesse Wilson
651d5669dc New function, EventListener.plus() (#9119)
Use this to support multiple EventListeners in the same
call.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-07 17:03:04 -04: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
Jesse Wilson
d41a755c7e Start publishing dispatcher queue events (#9111)
* Start publishing dispatcher queue events

* Update okhttp/src/commonJvmAndroid/kotlin/okhttp3/Dispatcher.kt

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-07 10:16:22 -04:00
Jesse Wilson
e6250bdb2d Introduce events for the dispatcher queue (#9106)
So event listeners can see how long calls are waiting for
resources to become available.

This is the API only. I'll do the implementation in
follow-up.

Also note that I'm going to try my best to implement
this event pair to only fire for calls that actually
spend time in the queue. Calls that are immediately
promoted out of the queue should not get events.
2025-10-06 09:40:20 -04:00
Jesse Wilson
4e7860212f New BufferedSocket class (#8977)
* New BufferedSocket class

I'm starting to push Okio's socket throughout OkHttp,
and it turns out what I usually want is a BufferedSocket
instead.

* Flush not emit

* Track exception messages

* Use flush more
2025-07-31 00:18:40 -04:00
Tobias Gesellchen
286623ac57 Add support for HTTP/1.1 connection upgrades (#8969)
* Give the CountDownLatch something to count

* Fix typo

* Connection Upgrade for HTTP1 status code 101

See https://datatracker.ietf.org/doc/html/rfc9110#name-101-switching-protocols

* use socket.asOkioSocket()

* add socket to api

* remove the specific check on tcp connection upgrades

* create a dedicated HttpUpgradesTest

* chore

* add more test cases

* spotlessApply

* Use more MockWebServer features in tests

* Forbid HTTP/2

* Hook into Exchange for connection pool management

* Test events on successful upgrade

* Release the request body after an upgrade fails

* Upgrades don't promise a response body

* SpotlessApply

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-07-28 10:39:28 -04:00
Jesse Wilson
6b134f769a Enable explicit API mode in mockwebserver3. (#8854)
Also remove @ExperimentalOkHttpApi in a few places.

Also rename 'shutdown' to 'close' in MockWebServer
and Dispatcher.

Also rename QueueDispatcher.enqueueResponse() to
QueueDispatcher.enqueue.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-14 12:09:26 -04:00
Jesse Wilson
80c71d2129 Temporarily remove ConnectionListener from the public API (#8831)
I'd like to update the API to improve observability into things
like ConnecitonPool, RoutePlanner, ConnectPlan, and ReusePlan.
And also into HTTP/2 internals like flow-control.

As-is this is more coupled to Call lifecycles and is somewhat
duplicative with ConnectionPool.

We'll do that work and make it a new public API, but we won't
have it in the public API at all for the 5.0 release.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-05-30 17:28:20 -04:00
Jesse Wilson
90d3a6b7c1 Be consistent about syntax to lock, wait, and notify (#8818)
The Dispatcher class is an outlier here as it cannot implement
the Lockable interface without that leaking into its public API.
We do without in that case.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-05-28 19:28:25 -04:00
Jesse Wilson
acd192ade5 Change the locking mechanism to 'synchronized' (#8817)
* Change the locking mechanism to 'synchronized'

We migrated to ReentrantReadWriteLock to better support Loom,
but now we can use synchronized and still support Loom.
This old mechanism may be faster than ReentrantReadWriteLock.

* Update okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/concurrent/Lockable.kt

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

---------

Co-authored-by: Jesse Wilson <jesse@swank.ca>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2025-05-28 13:15:47 -04:00
Jesse Wilson
2f6a27f048 Split EventListener.retryDecision into retryDecision and followUpDecision (#8796)
* Split EventListener.retryDecision into retryDecision and followUpDecision

retryDecision has an exception, and is related to
connectivity failures.

followUpDecision has an intermediate response, and is
related to redirects and auth challenges.

This drops the reason strings, which have 'logging brain'
and I want to push our users towards 'metrics brain'.

* Spotless

* apiDump

* Fix another test

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-05-27 10:58:02 -04:00
Jesse Wilson
27ddd2c286 Drop the findbugs dependency (#8769)
We don't need it.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-05-13 20:51:50 -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
Yuri Schimke
3319f24bf7 Add retryDecision event to track retry logic in EventListener (#8666)
* Add retryDecision event to track retry logic in EventListener

Introduced a new `retryDecision` event to improve observability of retry logic. This includes detailed reasons for retry decisions, enhancing debugging. Updated relevant tests, interceptors, and event handling to accommodate the new event.

It also cleanly signals the boundary before a prior request and the follow up.
2025-02-15 15:47:40 +00:00
Yuri Schimke
d212391897 remove unneeded TODO (#8637) 2024-12-28 12:19:31 +00:00
Yuri Schimke
5b2a1e139e Split okhttp core into Android and JVM (#8600) 2024-12-27 13:39:56 +00:00
Yuri Schimke
f07f4ccbd4 Call proxy selector on failure (#8415)
* Call proxy selector on failure

---------

Co-authored-by: Jesse Wilson <jesse@swank.ca>
2024-11-23 19:12:40 +00:00
Yuri Schimke
3e560892d4 Centralise more locks (#8389)
Refactor: Centralize lock management

This change centralizes the management of locks and conditions by introducing a centralised Locks registry. This allows for easier debugging and potential future improvements to lock usage.

The `withLock` and `newLockCondition` functions are now invoked through the `Locks` object, providing a central point of access.
2024-11-17 19:04:37 +00:00
Jesse Wilson
d0b6a464d8 Start fewer threads in TaskRunner (#8391)
We've got a race where we'll start a thread when we need
one, even if we've already started a thread. This changes
TaskRunner's behavior to never add a thread if we're
still waiting for a recently-added one to start running.

This is intended to reduce the number of threads contenting
for the TaskRunner lock as reported in this issue:

https://github.com/square/okhttp/issues/8388
2024-04-28 20:33:04 -04:00