* 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
* 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>
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>
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>
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>
* 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>
* 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>
* 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.
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.
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
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.
* 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
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.
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>
* 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
* 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
* 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
* 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)
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