* Add RequestBody.sha256()
* * SHA256 -> SHA-256
* Return ByteString, not String
* simplify test
* Move extension function to a regular class method
* Add @Throws(IOException::class)
* 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>
* 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>
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>
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.
* 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
* 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>
* 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>
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>
* 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>