Skip to content

Consider ForwardingRequestBody #9800

Open

Description

@JakeWharton

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).

Activity

  1. Amir-Golmoradi commented on Oct 21, 2026

    @Amir-Golmoradi
    Contributor

    Hi @JakeWharton , hope you had great day so far.

    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?

  2. JakeWharton commented on Oct 21, 2026

    @JakeWharton
    CollaboratorAuthor

    Yes, that's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions