1
0
mirror of https://github.com/square/okhttp.git synced 2025-08-07 12:42:57 +03:00

228 Commits

Author SHA1 Message Date
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
Yuri Schimke
d0d7557822 Move to centralised loom safe locks (#8371) 2024-04-20 18:03:43 +01:00
Jesse Wilson
689d38873f Revert "Move RealCall and RealConnection to loom safe locks (#8290)" (#8367)
This reverts commit a673f45ba6.
2024-04-17 06:15:48 +01:00
Jesse Wilson
6bc0862e4e Improve some code comments (#8361) 2024-04-15 10:55:09 -04:00
Yuri Schimke
a673f45ba6 Move RealCall and RealConnection to loom safe locks (#8290) 2024-04-15 08:37:21 +01:00
Jesse Wilson
822bad8169 Extract a test thread factory (#8356)
This is different from the production thread factory:
 - No daemon threads in tests. We don't need 'em.
 - Threads are numbered in tests. We do need that.
2024-04-11 18:09:35 -04:00
Jesse Wilson
27670f9eb1 Redo TaskFaker's internal queue (#8348)
* Redo TaskFaker's internal queue

Previously this used locks to stop threads from executing. Now
it uses a custom 'yield' function to accomplish a similar purpose.
The main benefit of the new approach is we're no longer subject
to unspecified lock release order - we maintain our own queue
and get true deterministic order of execution.

* Fix interruption

* Fixup tests

* Spotless

* Use an enum rather than two booleans
2024-04-10 21:59:58 -04:00
Evan Nelson
c9ba5d732b Support minimum connection pool size (#8287)
This PR adds support for configuring the connection pool to proactively create connections to specified hosts. This is useful for "prewarming" the connection pool before it starts being used.

The main public API change is adding `ConnectionPool.setPolicy(Address, AddressPolicy)`. A policy specifies how many _concurrent streams_ should be supported by the pool (which might be satisfied by a single http/2 connection or by N http/1.1 connections).

The main internal change is adding a new task queue to `RealConnectionPool` which checks to see if it needs to create new connections to satisfy existing policies. This task is enqueued any time a policy changes, a connection is closed, or an http/2 connection's settings decrease the number of concurrent streams supported.
2024-04-03 13:39:41 -07:00
Jesse Wilson
79aa6fc056 Test webSocketCloseTimeout (#8317)
* Test webSocketCloseTimeout

* Spotless
2024-04-01 10:21:25 -04:00
Jesse Wilson
e18252dd20 Extract an interface for a ConnectionUser (#8276)
This is working towards supporting pre-warmed connections
in ConnectionPool. We want to create connections without a
Call object.

Co-authored-by: Evan Nelson <enelson@squareup.com>
2024-03-06 09:33:38 -08: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
0e312d7804 Prepare to enable Spotless (#8179)
* Prepare to enable Spotless

I'm not super keen on any of these changes, but I am very
keen on having automatic formatting.

* Don't actually enable Spotless yet
2024-01-07 11:05:34 -05:00
Jesse Wilson
23d67c304f Switch to assertFailsWith (#8177)
* Switch to assertk.fail

* Use assertFailsWith

* More assertFailsWith

* Use more assertFailsWith

* More assertFailsWith

* More assertFailsWith

* Native image dependencies

* Move JUnit dependency

* Don't lock in a specific implementation class

* Missing finally
2024-01-06 00:31:00 -05:00
Jesse Wilson
eb6c016f6f Stop using AssertJ (#8174)
* Stop using AssertJ

This completes the migration to assertk.

* Fix a missing import

* Fix some type issues
2024-01-04 00:32:07 -05:00
Yuri Schimke
265cb04e99 Test with release build & update proguard config. (#8156) 2023-12-23 14:46:51 +00:00
Jesse Wilson
1561bbaeae Convert some tests to Kotlin (#8152)
* Rename .java to .kt without conversion

* Convert to Kotlin
2023-12-21 06:25:40 -05:00
Jesse Wilson
e285d4e68b Even more assertk (#8151)
* Even more assertk

When we split tests into multiplatform we switched them
from AssertJ to assertk. I'm migrating everything over to
assertk so that I can merge tests back together without
changing assertion APIs.

* Fixup some type conversion problems
2023-12-20 20:54:49 -05: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
Jesse Wilson
6b7b611308 Remove expect/actuals (#8147)
* Remove expect/actuals from okcurl

* Remove expect/actuals from okhttp-coroutines

* Remove expect/actuals from okhttp

* Remove expect/actuals from okhttp-testing-support

* Fixup build scripts
2023-12-19 07:37:45 -05:00
Benoît Quenaudon
68105a4832 Removing all JS variants (#8145) 2023-12-18 10:49:23 -05:00
Yuri Schimke
e2344c7277 Evict connection pool a second time after tests (#7819) 2023-05-14 09:02:17 +01:00
Yuri Schimke
f62fd47876 Fix websocket reconnect race condition (#7815) 2023-05-13 12:31:00 +01:00
Yuri Schimke
e882b4cdc9 Add flow control observability (#7810) 2023-05-10 09:45:54 +01:00
Jesse Wilson
0d39bc580a Run HttpUrl tests on all platforms (#7802) 2023-05-06 15:30:27 -04:00
Jesse Wilson
cfaefe00c9 Do IDNA mapping on Kotlin/JS (#7800) 2023-05-05 21:22:01 -04:00
Jesse Wilson
6204a3ec51 Make okhttp-testing-support a multiplatform project (#7797) 2023-05-04 07:53:29 -04:00
Yuri Schimke
f408411ff9 Avoid exposing internal methods (#7734) 2023-04-23 08:05:59 +01:00
Yuri Schimke
3db0d8279c Test for proxy location change (#7720) 2023-04-23 07:59:39 +01:00
Yuri Schimke
264d174347 Avoid failing on Loom. (#7716) 2023-02-18 15:26:25 +00:00
renovate[bot]
5ece5e4df7 Update dependency software.amazon.cryptools:AmazonCorrettoCryptoProvider to v2 (#7690)
* Update dependency software.amazon.cryptools:AmazonCorrettoCryptoProvider to v2

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2023-02-18 13:22:01 +00:00
Yuri Schimke
0061139174 Remove RealCall from ConnectionListener (#7681)
* Remove RealCall from ConnectionListener

* API

* API
2023-02-04 16:02:23 -05:00
Jesse Wilson
22fe120548 Delete some dead code (#7666)
Follow-up to https://github.com/square/okhttp/pull/7462/files
2023-01-22 21:46:03 -05:00
Yuri Schimke
33ace75841 Loom Support (#7367) 2023-01-03 10:07:36 +10:00
Yuri Schimke
13ac56ca0a Check for matching ConnectionEvent (#7612)
* Check for matching ConnectionEvent

* Fixes for API file

* Fix tests

* Fix cancel event logic
2023-01-02 11:24:01 -05:00
Jesse Wilson
847b5af240 Avoid InetAddress.getCanonicalHostName(). (#7607)
Just hard-coding 'localhost' is simpler and avoids problems where
the host machine's IP address has additional DNS registrations.

Closes: https://github.com/square/okhttp/issues/7603
2023-01-02 09:04:37 -05:00