Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apache HTTP client does not support GET requests with content #1442

Open
freva opened this issue Sep 1, 2021 · 1 comment
Open

Apache HTTP client does not support GET requests with content #1442

freva opened this issue Sep 1, 2021 · 1 comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@freva
Copy link

freva commented Sep 1, 2021

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

private static final String[] SUPPORTED_METHODS = {
HttpMethods.DELETE,
HttpMethods.GET,
HttpMethods.HEAD,
HttpMethods.OPTIONS,
HttpMethods.POST,
HttpMethods.PUT,
HttpMethods.TRACE
};

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:

if (getStreamingContent() != null) {
Preconditions.checkState(
request instanceof HttpEntityEnclosingRequest,
"Apache HTTP client does not support %s requests with content.",
request.getRequestLine().getMethod());
ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent());
entity.setContentEncoding(getContentEncoding());
entity.setContentType(getContentType());
if (getContentLength() == -1) {
entity.setChunked(true);
}
((HttpEntityEnclosingRequest) request).setEntity(entity);
}

but in this case getContentStreaming() is returning an com.google.api.client.http.EmptyContet due to googleapis/gax-java#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).

@Neenu1995 Neenu1995 added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Sep 1, 2021
@Jessicawy2333
Copy link

I am trying to set proxy with authentication for clients with google-cloud-compute, also by customizing http transport in ApacheHttpTransport.

I encounter the same exception - "Apache HTTP client does not support GET requests with content."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants