Skip to content

OkHttp transport rejects body-less POST/PUT/PATCH with IllegalArgumentException #21

Description

@OmarAlJarrah

Problem

RequestAdapter.adapt passes a null body straight to OkHttp:

val okhttpBody = request.body?.let { toOkHttpBody(it) }
builder.method(request.method.method, okhttpBody)   // RequestAdapter.kt:55-56

For POST/PUT/PATCH, OkHttp's Request.Builder.method throws IllegalArgumentException("method X must have a request body") when the body is null. A body-less POST is valid HTTP, and nothing stops a caller from building one: Request.RequestBuilder.build() only requires method and url (Request.kt:254-257) and Method carries no body-requirement metadata. Because the failure is an IllegalArgumentException (not an IOException), it also bypasses retry. The JDK transport does not have this problem, so behaviour differs across transports.

Proposed change

When body == null and the method permits/requires a body (POST/PUT/PATCH), pass an empty request body instead of null. Audit the JDK transport for parity (BodyPublishers.noBody()).

Acceptance

  • Body-less POST/PUT/PATCH dispatches through the OkHttp transport
  • Parity test across OkHttp and JDK transports
  • Regression test for the previously-throwing path

Priority: high · Effort: small

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsdk-coresdk-core toolkit

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions