Skip to content

OkHttp HttpClient implementation ignores Request method for requests with no payload #5423

@manusa

Description

@manusa

Describe the bug

OkHttpclientImpl doesn't consider the provided request method for those requests which don't provide a payload body. These requests are all treated as GET regardless of what the user might have provided through a raw request.

Given the following if-else clause:

The execution jumps straight to

request.headers().entrySet().stream()
.forEach(e -> e.getValue().stream().forEach(v -> requestBuilder.addHeader(e.getKey(), v)));

since there is no request payload.

The requestBuilder.method is never set.

Fabric8 Kubernetes Client version

SNAPSHOT

Steps to reproduce

@Test
void postOk() {
  // Given
  server.expect()
    .post()
    .withPath("/api/post/ok")
    .andReturn(200, "ok")
    .once();
  // When
  final String result = client.raw("/api/post/ok", "POST", null);
  // Then
  assertThat(result).isEqualTo("ok");
}

Expected behavior

The sent method should be the one provided by the user.

Runtime

Kubernetes (vanilla), OpenShift

Kubernetes API Server version

next (development version)

Environment

Windows, Linux, macOS

Fabric8 Kubernetes Client Logs

No response

Additional context

Might relate to #5422

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions