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

572 Commits

Author SHA1 Message Date
Jesse Wilson
bc8df40582 Release OkHttp 5.5.1 2026-10-22 12:15:31 +08:00
Jesse Wilson
a94bdf1520 Prepare for release 5.5.0. 2026-08-16 12:08:03 -04: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
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
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
Jesse Wilson
61423f472d Prepare for release 5.4.0. 2026-06-08 15:34:43 -04: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
Yuri Schimke
9e9aab7eee Introduce build-logic decoupled convention plugins (#9289)
Use for 1 feature, publishing. And also move current buildSrc logic there.

First step to cleaning up build logic generally.
2026-02-01 16:35:35 +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
7f3a220877 Switch to Dokka v2 (#9263)
* Update Dokka to v2

update configuration to use experimental V2 plugin mode and adjust documentation generation scripts.
2026-01-25 12:37:13 +00:00
Jesse Wilson
0960b47ec2 Prepare for release 5.3.0. 2025-10-30 17:39:59 -04:00
Jesse Wilson
dad534a815 Put 5.2.1 in the changelog 2025-10-09 19:13:15 -04:00
Jesse Wilson
2a95ed0873 Prepare for release 5.2.0. 2025-10-07 11:47:25 -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
a5f8e4e5cb Add test that covers MockWebServer and URLConnection with 100-Continue (#8995) 2025-08-03 23:38:00 +01:00
renovate[bot]
cf4b91189c Update com.squareup.okio to v3.16.0 (#8975)
* Update com.squareup.okio to v3.16.0

* Don't crash getting FakeSocket.inputStream

* delay creating buffered socket in MWS

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2025-08-02 21:36:00 +01: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
Jesse Wilson
3bafcf16fb Re-implement web sockets support on the new Response.socket feature (#8974)
* Re-implement web sockets support on the new Response.socket feature

* Explain why we accept buffered streams
2025-07-29 18:04:11 -04:00
Jesse Wilson
7d53252fea Use okio.Socket internally in OkHttp connections (#8973)
* Use okio.Socket internally in OkHttp connections

* Spotless

* Fix connection close timing

* Accept 'Socket is closed' or 'Socket closed'

* Another 'Socket is closed' message difference

* Rollback attempt to defer buffering source and sink

With H2_PRIOR_KNOWLEDGE the server can send settings
before we've sent anything.

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-07-29 17:11:09 -04:00
Jesse Wilson
88593f8c28 New MockWebServerSocket helper class (#8972)
* New MockWebServerSocket helper class

This is work towards switching to use okio.Socket
as the implementation of web sockets.

* Fix RecordedRequestTest

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-07-29 08:43:16 -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
HyeokJun Kwon
a1a86c5774 Updated the readme documentation for mockwebserver #8910 (#8922)
* mockwebserver3 doc update
* convert java to kotlin
* Add Kotlin code to mockwebserver3 documentation

---------

Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2025-07-19 14:40:52 +01:00
Jesse Wilson
133dd83079 Update code samples for mockwebserver3 (#8923)
Closes: https://github.com/square/okhttp/issues/8920

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-07-09 20:57:24 -04:00
Jesse Wilson
d2dd180697 Prepare for release 5.1.0. 2025-07-07 15:32:33 -04:00
Yuri Schimke
e41ff18df8 Link to new mockwebserver artifacts (#8911) 2025-07-04 09:56:14 -04:00
Jesse Wilson
1b703d52a9 Prepare for release 5.0.0. 2025-07-03 10:43:08 -04:00
Jesse Wilson
4d0986be40 Change RecordedRequest.chunkSizes to be nullable (#8872)
* Change RecordedRequest.chunkSizes to be nullable

Now that it's all Kotlin we can usefully distinguish
between null (not chunked) and empty list (chunked with
zero bytes).

Also remove the experimental annotation from RecordedRequest
and delete the experimental annotation.

* apiDump

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-21 16:36:35 -04:00
Jesse Wilson
f745695087 Replace SocketPolicy with a new type, SocketEffect (#8870)
* Replace SocketPolicy with a new type, SocketEffect

SocketPolicy encapsulated two things:
 - a trigger (request start, response body, etc)
 - an effect (close the socket, close the stream, stall, etc.)

It also had some special cases for effects like
failing the TLS handshake.

With this PR there's a new class, SocketEffect, that determines
what to do. It's assigned to one of 5 fields for different
triggers.

# Conflicts:
#	mockwebserver/src/main/kotlin/mockwebserver3/MockWebServer.kt

* apiDump

* Track API change

* Track more API changes

* Spotless

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-20 07:46:46 -04:00
Jesse Wilson
0a902f3d28 Use HTTP/2 in RecordedRequest (#8869) 2025-06-19 23:33:28 -04:00
Jesse Wilson
36ed3452fe Add a connectionIndex field to RecordedRequest (#8866)
Also rename 'sequenceNumber' to 'exchangeIndex'.
This may be useful to test features like connection
reuse.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-19 07:44:16 -04:00
Jesse Wilson
935534dca4 Permit RecordedRequest.body to be null or empty (#8865)
* Permit RecordedRequest.body to be null or empty

Null if we didn't capture a body, and empty if we
captured an empty body.

* Track API change

* Fixup more tests

* spotless

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-18 11:13:15 -04: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
Jesse Wilson
b9a1a5dd80 Change some MockWebServer ergonomics (#8861)
* Change some MockWebServer ergonomics

Now calling MockWebServer.port and similar functions will
not implicity start the server. It is instead necessary to
explicitly call the start() function.

The problem with the old behavior was that reading the
port field could fail with an IOException, which is weird
behavior for reading a property.

* Fixup test

* Fix another test

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-17 20:19:42 -04:00
Jesse Wilson
dfd1dffb3c Decompose the request line into individual properties (#8860)
* Decompose the request line into individual properties

Replace the 'path' property with the URL's encodedPath
property.

Rename the 'requestUrl' property to 'url'.

* Spotless

* Fix up DnsOverHttpsTest

* Fix some test failures
2025-06-16 20:47:36 -04:00
Jesse Wilson
33b093a86c Stabilize the JUnit 4 API (#8857)
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-16 18:36:18 -04:00
Jesse Wilson
db836de300 Fix a liveness bug in MockWebServer (#8858)
* Fix a liveness bug in MockWebServer

It was possible to configure delays that would be honored
after MockWebServer was shut down. With this fix any
delay will be abandoned once the server is closed.

* Update mockwebserver/src/main/kotlin/mockwebserver3/internal/SleepNanos.kt

Co-authored-by: Jake Wharton <jw@squareup.com>

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
Co-authored-by: Jake Wharton <jw@squareup.com>
2025-06-16 11:00:51 -04:00
Jesse Wilson
b4181838a3 Change RecordedRequest.body to a ByteString (#8856)
* Change RecordedRequest.body to a ByteString

Immutable is good.

* apiDump

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-14 14:13:40 -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
817b7a89d4 Change MockWebServer to use Okio's new Socket interface (#8853)
* Change MockWebServer to use Okio's new Socket interface

This replaces the Stream interface introduced in a recent
alpha release.

* apiDump

* Only buffer once

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-13 19:09:36 -06:00
Jesse Wilson
5eecd519aa Finalize the new API for MockResponse (#8837)
* Finalize the new API for MockResponse

It's a value object with a bunch of fields, and a builder.

* Tunnel then body

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-03 13:10:21 -04:00
Jesse Wilson
6de88ec621 TrailersSource, a new public API for HTTP trailers (#8829)
* TrailersSource, a new public API for HTTP trailers

This doesn't change much.

The new interface replaces a Kotlin lambda that had
similar behavior, though that lambda wasn't specified
as thoroughly.

We now permit calls to Response.trailers() before the
entire response body is consumed. But when such calls are
made the response body is discarded first. This could be
a bit of a surprise to users, especially users who do an
additional layer of buffering over their ResponseBody
because it could yield latent failures.

But I think it's better behavior overall, especially since
it's possible data binding layers might not consume the
entire response body in all cases. For example, a JSON
library might not read to the very end of the response
if it has received a terminating '}' byte.

The riskiest part of this change is when ResponseBodySource
self-reports as complete. Previously it would self-report
as complete when it returned as many bytes as promised
in the Content-Length. With this change it will now only
report itself complete when it receives a definitive EOF
on the stream, signaled by a -1 byte count on a read. This
is because only when the EOF is received can we be sure
that the trailers are received, and we must not unhook
the Exchange from the Call until that happens. The previous
behavior could make Call.cancel() no-op even if we were
blocked waiting on trailers.

* apiDump

* Attempt to get more tests passing

* Don't wait for stream EOF to release the stream

One of our tests caught a situation where we were waiting
for the caller to read the EOF when we didn't need to.

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-06-02 10:42:05 -04:00
Jesse Wilson
2bc0b0f25d Use SHOUTY_CASE for static constants (#8802)
OkHttp has lots of constants defined from before it was a
Kotlin library, and I'd rather the library be self-consistent
than consistent with Kotlin idioms.

As a bonus we get to remain consistent with Java idioms.
I'd love a Kotlin mechanism to use @JvmField and @JvmName
at the same time, but I can't figure out how.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-05-27 10:51:25 -04:00
Yuri Schimke
e7b86fed23 Fix test with latest JDKs (#8765)
* Fix test with latest JDKs

Change in https://bugs.openjdk.org/browse/JDK-8335135

> HttpInputStream does not throw IOException when response is truncated

* Update mockwebserver/src/test/java/mockwebserver3/MockWebServerTest.kt

Co-authored-by: Jake Wharton <github@jakewharton.com>

---------

Co-authored-by: Jake Wharton <github@jakewharton.com>
2025-05-10 21:11:56 +01: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
木葉 Scarlet
33854ec0d6 Empty constant of Headers, RequestBody, ResponseBody (#8720)
* `Empty` constant of Headers, RequestBody, ResponseBody

removed informal internal constants
2025-04-05 12:39:37 +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]
8cc665f95a Update org.bouncycastle to v1.79 (#8441)
* Update org.bouncycastle to v1.79

* Handle UnsupportedOperationException – if the underlying provider does not implement the operation

* Handle BC requirements on the key manager

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2024-12-28 15:22:24 +00:00
Jesse Wilson
23dbc1e643 Use the name webSocketCloseTimeout (#8316)
The name closeTimeout might be mistaken as a regular HTTP
option.
2024-03-31 13:16:15 -04:00
Arlo O'Keeffe
66ae138b17 allow configuring web socket close timeout (#8189) 2024-03-31 11:45:15 -04:00
Jesse Wilson
373822e239 Mechanically tag all new APIs as @ExperimentalOkHttpApi (#8216)
* Mechanically tag all new APIs as @ExperimentalOkHttpApi

In a follow-up PR I intend to remove the annotation on any
API that we're willing to commit to for OkHttp 5.0.0.

In a follow-up PR I'd also like to hide all remaining
APIs from Java langauge callers.

* Opt-in ExperimentalOkHttpApi for Android projects too

---------

Co-authored-by: Benoit Quenaudon <benoit@quenaudon.com>
2024-01-23 09:31:42 -05:00