googleapis / googleapis/google-api-java-client

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

Đang mở
#1,548 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
priority: p4 type: feature request
Ngôn ngữ chính
Java
Star
1.5k
Fork
772
Merge trung bình
1 giờ 44 phút
Pull request đã merge (30 ngày)
1

Mô tả

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`.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.