You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to change the Content-Type of a body, and so I'm wrapping it with my own RequestBody subclass. However, I'm not forced to forward isOneShot() or isDuplex() and so I didn't. Can I add those and forward them? Sure, but I'm also setting myself up for failure when another function is added in the future.
A ForwardingRequestBody which accepts a RequestBody and forwards all functions handles that for me. Further more, if new functions are added and OkHttp is upgraded my library inherits that behavior for free (without recompilation & release, too).
There's already a ForwardingRequestBody in okhttp-testing-support, though it doesn't forward isOneShot().
I'd start from that implementation, move it into the main module, and cover delegation and overriding contentType() while preserving one-shot and duplex behavior. I'd also update the JVM and Android API snapshots.
Does that approach make sense, and is anyone already working on it?
Activity
Amir-Golmoradi commentedon Oct 21, 2026
Hi @JakeWharton , hope you had great day so far.
There's already a
ForwardingRequestBodyinokhttp-testing-support, though it doesn't forwardisOneShot().I'd start from that implementation, move it into the main module, and cover delegation and overriding
contentType()while preserving one-shot and duplex behavior. I'd also update the JVM and Android API snapshots.Does that approach make sense, and is anyone already working on it?
JakeWharton commentedon Oct 21, 2026
Yes, that's fine.