Apache HTTP client does not support GET requests with content

Open
#1,442 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java

Research direction

Start with google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpRequest.java at the precondition mentioned in the report, then compare the GET handling in NetHttpTransport.java. Reproduce the provided ImagesClient example with ApacheHttpTransport and verify that GET content handling no longer fails while PATCH remains supported.

Written by the indexing model from the issue text.

Description

type: feature request

I'm trying to update a resource with google-cloud-compute-1.3.0, the client does this using HTTP PATCH. This is not supported with the default NetHttpTransport (#1316): https://github.com/googleapis/google-http-java-client/blob/7ebc6ca7807424b6372f1b52ac7b129752a9acf5/google-http-client/src/main/java/com/google/api/client/http/javanet/NetHttpTransport.java#L68-L76

To workaround that, I set the HTTP transport to ApacheHttpTransport, but then other requests fail with

Caused by: java.lang.IllegalStateException: Apache HTTP client does not support GET requests with content.
	at com.google.common.base.Preconditions.checkState(Preconditions.java:469)
	at com.google.api.client.util.Preconditions.checkState(Preconditions.java:113)
	at com.google.api.client.http.apache.v2.ApacheHttpRequest.execute(ApacheHttpRequest.java:60)
	at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1012)
	at com.google.api.gax.httpjson.HttpRequestRunnable.run(HttpRequestRunnable.java:143)
	... 6 more

This precondition is run when getContentStreaming() != null: https://github.com/googleapis/google-http-java-client/blob/7ebc6ca7807424b6372f1b52ac7b129752a9acf5/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpRequest.java#L59-L71
but in this case getContentStreaming() is returning an com.google.api.client.http.EmptyContet due to https://github.com/googleapis/gax-java/pull/648

I think this precondition needs to be relaxed and be in-line with NetHttpTransport, which does support GET requests with non-null getContentStreaming().

Environment details
  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    google-cloud-compute-1.3.0
  2. OS type and version: RHEL 8.3
  3. Java version: 11.0.10
  4. google-http-client version(s): 1.39.2
Code example
TransportChannelProvider transportChannelProvider = InstantiatingHttpJsonChannelProvider.newBuilder().setHttpTransport(new ApacheHttpTransport()).build();
ImagesSettings settings = ImagesSettings.newBuilder().setTransportChannelProvider(transportChannelProvider).build();
try (ImagesClient client = ImagesClient.create(settings)) {
    client.list("centos-cloud");
}

Will fail with the stacktrace above. Removing either .setTransportChannelProvider() or .setHttpTransport() (so that it defaults to NetHttpTransport) will fix this issue (but then PATCH doesn't work).

Dominant language
Java
Stars
1.4k
Forks
476
Avg merge
10h 47m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-http-java-client

All issues in googleapis/google-http-java-client

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.