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

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

Open
llbrt opened this issue Jul 7, 2020 · 1 comment
Labels
priority: p4 type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@llbrt
Copy link

llbrt commented Jul 7, 2020

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.

@llbrt llbrt changed the title Issue with Jetty on empty content POST/PUT/PATCH (consider disabling gzip all the time) Issue with Jetty on POST/PUT/PATCH with empty content (consider disabling gzip all the time) Jul 7, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Jul 8, 2020
@chingor13 chingor13 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jul 20, 2020
@yoshi-automation yoshi-automation removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Jul 20, 2020
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Oct 18, 2020
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jan 3, 2021
@chingor13 chingor13 added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 5, 2021
@yoshi-automation yoshi-automation removed the 🚨 This issue needs some love. label Jan 5, 2021
@clementdenis
Copy link

More recent Jetty versions (the one currently used by Google App Engine Standard for Java 8) will fail with a slightly different error (415 instead of 501)

org.eclipse.jetty.http.BadMessageException: 415: Unsupported Content-Encoding at org.eclipse.jetty.server.Request.extractContentParameters(Request.java:528) at org.eclipse.jetty.server.Request.getParameters(Request.java:435) at org.eclipse.jetty.server.Request.getParameter(Request.java:1075)

Any chance this could be fixed someday, as this is clearly a regression?

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

No branches or pull requests

5 participants