1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-12 10:23:16 +03:00
Commit Graph

6082 Commits

Author SHA1 Message Date
Jesse Wilson
a8b8dc5d80 Prepare for release 5.2.1. parent-5.2.1 2025-10-09 19:01:30 -04:00
Jesse Wilson
7d7bdc69c8 Upgrade to Okio 3.16.1 (#9131)
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-09 19:01:12 -04:00
Jesse Wilson
2a95ed0873 Prepare for release 5.2.0. parent-5.2.0 2025-10-07 11:47:25 -04:00
Jesse Wilson
acfae325f0 Revert "Add minimal HttpLoggingInterceptor support for streaming request and responses. (#8993)" (#9115)
This reverts commit c998c2c57b.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-07 11:15:46 -04:00
Jesse Wilson
d82e8750c4 Put Brotli and Gzip in top-level files (#9116)
This doesn't have any impact on compatibility.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-07 11:15:28 -04:00
Tobias Gesellchen
d4a5be134e Fix RequestBody events on upgraded connections (#8970)
* Add SocketSink{Start,End} events

* Add SocketSource{Start,End} events

* Emit SocketSink/Source events

* Ensure same connection

* Chore

* Chore

* There and back again

* Update okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/connection/Exchange.kt

* Update okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/connection/Exchange.kt

---------

Co-authored-by: Jesse Wilson <jesse@swank.ca>
2025-10-07 10:17:39 -04:00
Martin Bonnin
112a19d5e4 Add RequestBody.sha256() (#9109)
* Add RequestBody.sha256()

* * SHA256 -> SHA-256
* Return ByteString, not String

* simplify test

* Move extension function to a regular class method

* Add @Throws(IOException::class)
2025-10-07 10:16:29 -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
c06ff312b2 Get Content-Type from the request body (#9113)
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-06 19:46:55 -04:00
Jesse Wilson
fdac86bb90 Make Request.toCurl work more like Chrome's 'copy as cURL' (#9112)
* Make Request.toCurl work more like Chrome's 'copy as cURL'

Changes:
 - single quotes
 - URL first
 - omit the default method

Also change binary detection to use isProbablyUtf8
instead, which is promoted to the main okhttp module.

Also replace the BinaryMode enum with a boolean to
optionally not include the body.

* More aggressive character escaping

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-06 18:47:06 -04:00
Hamza Badar
fa84a6e0d7 feat: add curl() method to Request for generating cURL commands (#8897)
* feat: add curl() method to Request for generating cURL commands

This commit introduces a new `curl()` method in the `Request` class that generates a cURL command equivalent for the HTTP request. This is useful for debugging, logging, and reproducing requests outside of the application.

Key features:
- Includes HTTP method (`-X`), headers (`-H`), and request body (`--data`) if present.
- Handles escaping of special characters in body content.
- Appends the request URL.
- Provides KDoc consistent with the existing codebase.
- Added unit tests for:
  - GET requests with headers.
  - POST requests with complex JSON bodies containing nested objects and arrays.

* feat: add curl() method test cases to RequestTest for generating cURL commands

* update okhttp api

* Use Buffer for request body reading and improve curl generation

- Replace ByteArray-based reads with okio.Buffer for efficiency
- Detect binary data by inspecting bytes instead of relying on Content-Type
- Add BinaryMode options: HEX, OMIT, FILE, STDIN
- Default binary mode is now STDIN (`--data-binary @-`)

* update toCurl method Doc
- use intArrayOf instead of listOf
- update binaryMode param default value
- don't clone buffer twice

---------

Co-authored-by: Yuri Schimke <yuri@schimke.ee>
Co-authored-by: Hamza Badar <hamzabadar@Hamzas-MacBook-Air.local>
2025-10-06 16:53:35 -04:00
Jesse Wilson
e3e996095b Use a single synchronized block in Dispatcher (#9110)
Previously we had synchronized blocks preceding calls
to promoteAndExecute, plus the synchronized blocks in
that function itself.

This is intended to make it easier to publishg the right
events for dispatcherQueueStart and dispatcherQueueEnd
when an enqueued call can skip the queue.

Also note that this should fix some corner-cases around
unnecessary calls to idleCallback when the executor is
already shut down.

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-06 14:34:01 -04:00
Jesse Wilson
90079a10a3 Allow HTTP/1.1 Upgrades with empty RequestBody (#9105)
* Allow HTTP/1.1 Upgrades with empty RequestBody

See https://docs.docker.com/reference/api/engine/version/v1.51/#tag/Container/operation/ContainerAttach

* Rewrite the upgrade require() call

This is easier for me to understand.

---------

Co-authored-by: Tobias Gesellchen <tobias@gesellix.de>
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-06 10:05:30 -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
Martin Bonnin
9e58516947 Add KDoc for Request.Builder.query() (#9107) 2025-10-05 08:03:06 +01:00
Yuri Schimke
22786bd3f9 Enable QUERY caching via cacheUrlOverride (#9101)
* Enable QUERY caching via cacheUrlOverride

Reuse tests from https://github.com/square/okhttp/pull/9027

But with minimal support requiring a specific override.

* fix comment
2025-10-03 13:41:45 -04:00
Yuri Schimke
eb2e5a8b54 Fix comments from modules PR (#9102) 2025-10-03 09:35:58 +01:00
Jesse Wilson
185c408c62 Revert "refactor(SSE): move static functions to extensions (#9010)" (#9098)
* Revert "refactor(SSE): move static functions to extensions (#9010)"

This reverts commit 09fb9a448a.

* Remove unnecessary control flow from a test (#9099)

Co-authored-by: Jesse Wilson <jwilson@squareup.com>

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-03 08:51:20 +01:00
Jesse Wilson
7721acd852 Revert "Add QUERY caching support (#9027)" (#9097)
* Revert "Add QUERY caching support (#9027)"

This reverts commit bc269e3d5a.

* Also don't cache QUERY for now

Will bring this back when we use cacheUrlOverride for QUERY

---------

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
2025-10-03 08:50:58 +01:00
renovate[bot]
fa783c3dda Update gradle/actions action to v5 (#9095)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-10-01 18:46:11 -04:00
renovate[bot]
3df36fdffa Update dependency com.puppycrawl.tools:checkstyle to v11.1.0 (#9091)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-28 13:13:55 -04:00
renovate[bot]
60680e282d Update dependency org.apache.httpcomponents.client5:httpclient5 to v5.5.1 (#9089)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-27 14:12:07 -04:00
renovate[bot]
7defade315 Update dependency com.gradleup.shadow:shadow-gradle-plugin to v9.2.2 (#9087)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-26 08:06:27 -04:00
renovate[bot]
74ae35cecf Update dependency org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin to v0.11.1 (#9086)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-25 14:45:55 -04:00
renovate[bot]
1585478fc2 Update dependency maven-wrapper to v3.3.4 (#9085)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-25 19:22:49 +01:00
renovate[bot]
1495b28568 Update dependency com.diffplug.spotless:spotless-plugin-gradle to v8 (#9083)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-24 18:04:13 -04:00
renovate[bot]
cee8d4d015 Update dependency com.gradleup.shadow:shadow-gradle-plugin to v9.2.1 (#9082)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-24 09:19:51 -04:00
Narissa
eb6c29ba99 Update BUG-BOUNTY.md (#9081) 2025-09-23 17:23:42 -04:00
renovate[bot]
942ba2c48f Update actions/setup-java action to v5 (#9079)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-21 10:14:37 +01:00
Yuri Schimke
bc4fffe1f3 Fix merge issue with modules and logging (#9078) 2025-09-21 09:30:26 +01:00
renovate[bot]
195c54d7bf Update plugin org.gradlex.extra-java-module-info to v1.13.1 (#9076)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-21 07:45:42 +01:00
renovate[bot]
2893287889 Update actions/checkout action to v5 (#9077)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-21 07:45:35 +01:00
renovate[bot]
020d83fbc3 Update dependency maven-wrapper to v3.3.4 (#9063)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-21 07:45:20 +01:00
Etienne Dechamps (Google)
c1989e82e5 Change Gradle version from 9.0.0 to 8.14.3 (#9071)
Gradle 9.0.0 is not supported by the Android Gradle Plugin (AGP), and
attempting to use it tends to cause various build breakages caused by
deprecated Gradle methods going away. AGP works with Gradle 8.x, though.

See also: https://developer.android.com/build/releases/gradle-plugin#updating-gradle

The reason why the breakage is not obvious is because when using Android
Studio it will ignore this file and just use its bundled Gradle version.
But that is not true in other cases, such as when using the VS Code
Gradle extension.

Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2025-09-21 07:40:38 +01:00
Jesse Wilson
8f88fdbf1d Discard trailing data after a deflated message (#8610)
We can recover from this and it seems like the least worst of our
options.

Closes: https://github.com/square/okhttp/issues/8551

Co-authored-by: Jesse Wilson <jwilson@squareup.com>
Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2025-09-21 07:26:07 +01:00
Yuri Schimke
c998c2c57b Add minimal HttpLoggingInterceptor support for streaming request and responses. (#8993)
* Add a minimal HttpLoggingInterceptor support for streaming.

These use cases are much more common with protocols like MCP adopting
Streaming HTTP.

https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http
2025-09-21 07:24:36 +01: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
renovate[bot]
d36fa42758 Update dependency org.graalvm.nativeimage:svm to v25 (#9068)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-20 18:02:57 +01:00
Mario Daniel Ruiz Saavedra
bc269e3d5a Add QUERY caching support (#9027)
* Add QUERY caching support
* Address PR comments (cacheOverride, broken tests)
* Move cache oneshot body checks to the get method
* Avoid changing cache format
* Stream request body in hash

---------

Co-authored-by: Yuri Schimke <yuri@schimke.ee>
2025-09-20 17:48:07 +01:00
renovate[bot]
e985b66edb Update Gradle to v9.1.0 (#9072)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-18 16:55:41 -04:00
renovate[bot]
1536f99f07 Update org.bouncycastle to v1.82 (#9069)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-17 15:55:16 +01:00
Yuri Schimke
3abc0400e4 Also check TlsVersion (#9066)
It's implied by cipher suites, but for completeness.
2025-09-16 08:21:43 +01:00
renovate[bot]
ea11e718b0 Update dependency com.google.devtools.ksp:symbol-processing-gradle-plugin to v2.2.20-2.0.3 (#9064)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-11 22:08:29 -04:00
renovate[bot]
6d4f4c46b6 Update dependency com.google.devtools.ksp:symbol-processing-gradle-plugin to v2.2.20-2.0.2 (#9062)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-10 17:01:15 -04:00
renovate[bot]
9b7dd356ce Update dependency androidx.activity:activity-ktx to v1.11.0 (#9061)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-10 19:58:34 +01:00
renovate[bot]
c65d8cb3ed Update kotlin monorepo to v2.2.20 (#9060)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-10 08:19:43 -04:00
renovate[bot]
085572d1a2 Update dependency de.mannodermaus.gradle.plugins:android-junit5 to v1.13.4.0 (#9057)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-07 10:40:01 +01:00
renovate[bot]
6c0c159d49 Update dependency de.mannodermaus.gradle.plugins:android-junit5 to v1.13.3.0 (#9056)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-06 17:53:31 -04:00
renovate[bot]
3d3fc41305 Update dependency org.eclipse.platform:org.eclipse.osgi to v3.23.200 (#9055)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-06 13:54:10 -04:00
renovate[bot]
861d57a617 Update dependency de.mannodermaus.gradle.plugins:android-junit5 to v1.13.2.0 (#9052)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-09-06 09:08:00 -04:00