* Read RequestBody before Connection Upgrade
* Be more strict on event lifecycle for upgrades (#9170)
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
---------
Co-authored-by: Jesse Wilson <jesse@swank.ca>
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
Originally I was planning on implementing tags on
Request only, but that design broke as soon as any
interceptor used Request.newBuilder() to create a
copy of the Request - the instance that received the
tags might not be the instance that needed them.
Instead I'm introducing this behavior on the Call
object, which behaves less like a value. I expect
that users' expected lifetimes of tags will work
naturally this way.
It is an API hazard that we have tags on both
Requests and Calls. Perhaps if given the opportunity
to do it over, I'd omit support for tags on Requests.
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
* New datastructure to hold Tags
We have been using MutableMap and Map. These have worked
fine.
But we'd like to soon support mutating tags on an existing
Request object, which I'd like to do without a ton of
collections or concurrency overhead. Instead we can do some
lock-free stuff, which needs a simple data structure as a
starting point.
* Fill in some type parameters
* Update junit configuration in renovate.json
avoid major updates
* Add monorepo and recommended groups to Renovate config
* Remove groupName from junit-framework configuration
Removed groupName for junit-framework monorepo.
* Update Renovate config by removing ignored dependencies
Removed ignored dependencies from Renovate configuration.
* Update Renovate configuration to use junit5
* Make tests fail on UnsupportedOperationException
Will fail without the okio fix.
```
09:14:49.703 E FATAL EXCEPTION: MockWebServer TaskRunner (Ask Gemini)
Process: okhttp.android.test.test, PID: 10087
java.lang.UnsupportedOperationException
at javax.net.ssl.SSLSocket.shutdownOutput(SSLSocket.java:851)
at okio.internal.DefaultSocket$SocketSink.close(DefaultSocket.kt:95)
at okio.ForwardingSink.close(ForwardingSink.kt:37)
at mockwebserver3.internal.MockWebServerSocket$sink$1.close(MockWebServerSocket.kt:69)
at okio.RealBufferedSink.close(RealBufferedSink.kt:287)
at okhttp3.internal.http2.Http2Writer.close(Http2Writer.kt:331)
at okhttp3.internal.http2.Http2Connection.close$okhttp(Http2Connection.kt:474)
at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:638)
at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke(Http2Connection.kt:619)
at okhttp3.internal.concurrent.TaskQueue$execute$1.runOnce(TaskQueue.kt:112)
at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:81)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
```
* cleanup
* Fix SSL Handshake issue affecting MockWebserver on Android 24
Only called in MWS, but fails on API 24 when called. Adds a single Junit 4 test to run on Android 21-24.
Add a test since Junit 5 wasn't running on older devices.
* fix version number
* reformat
* reformat
There's only one implementation in use, and so I'm
inlining it to call through what it ultimately does.
My motivation is to avoid retaining a reference to an
EventListener anywhere, because that value is going
from immutable to mutable.
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
It's currently unused.
I'd like to bring this feature back soon, but using
regular Calls to make it happen rather than having
Connections created without a Call object. That should
avoid some special cases.
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
* 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>