googleapis / googleapis/google-api-java-client

Issue with Jetty on POST/PUT/PATCH with empty content (consider disabling gzip all the time)

Abierto
#1,548 1 comentario 0 reacciones 0 asignados Ver en GitHub
priority: p4 type: feature request
Lenguaje dominante
Java
Estrellas
1.5k
Forks
772
Merge medio
1 h 44 min
PR fusionados (30 d)
1

Descripción

When a HTTP request has an empty content (no payload) for a POST/PUT/PATCH, a Jetty server fails with the following stack for a client request created by this API with the default parameters:
```
org.eclipse.jetty.http.BadMessageException: 501: Unsupported Content-Encoding
at org.eclipse.jetty.server.Request.extractContentParameters(Request.java:517)
at org.eclipse.jetty.server.Request.getParameters(Request.java:430)
at org.eclipse.jetty.server.Request.getParameter(Request.java:1059)
```
It fails to analyse parameters because the content-size is not set and the headers are not consistent. Here are the default headers:
```
Accept-Encoding: gzip
Authorization: Bearer ya29.a0AfH6SMDK...
User-Agent: Integration Tests Google-API-Java-Client/1.30.9 Google-HTTP-Java-Client/1.35.0 (gzip)
x-goog-api-client: gl-java/11.0.7 gdcl/1.30.9 linux/5.3.0
Content-Encoding: gzip
```
On a previous version of this lib, the Content-Size was set to 27, which is the compression of the empty content.

When the compression is disabled (`.setDisableGZipContent(true)`), the headers are ok and it works well with Jetty:
```
Accept-Encoding: gzip
Authorization: Bearer ya29.a0AfH6SMDK...
User-Agent: Integration Tests Google-API-Java-Client/1.30.9 Google-HTTP-Java-Client/1.35.0 (gzip)
x-goog-api-client: gl-java/11.0.7 gdcl/1.30.9 linux/5.3.0
Content-Length: 0
```

For this kind of request in particular, with empty content in general (when the content size can be determined), the field `disableGZipContent` in the class `AbstractGoogleClientRequest` should be ignored and the compression always disabled. This will avoid some tricky errors with the default parameters of an `AbstractGoogleClientRequest` and avoid unnecessary compression.

In `com.google.api.client.googleapis.services.AbstractGoogleClientRequest`, around line 426, there is a few lines handling this kind of request
```
// custom methods may use POST with no content but require a Content-Length header
if (httpContent == null && (requestMethod.equals(HttpMethods.POST)
|| requestMethod.equals(HttpMethods.PUT) || requestMethod.equals(HttpMethods.PATCH))) {
httpRequest.setContent(new EmptyContent());
}
```
You may force the disabling of the compression just after to really have the `Content-Length header`.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.