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

NetHttpTransport drops Content-Length header when posting 0-length data #115

Closed
wonderfly opened this issue Jan 9, 2015 · 4 comments
Closed
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@wonderfly
Copy link
Contributor

From robert.c...@gmail.com on May 17, 2012 16:42:37

Version of google-http-java-client (e.g. 1.5.0-beta)? 1.8.3-beta Java environment (e.g. Java 6, Android 2.3, App Engine)? Java 6 Describe the problem. When posting a request of zero bytes, the "Content-Length" header is dropped. I noticed this when using the Google Http Client to write to
Google Cloud Storage. I'm trying to leverage the resumable uploads feature described here: https://developers.google.com/storage/docs/developer-guide#resumable "Step 1" indicates that the request must be a POST, where content length is set to zero.

Here's a trace of the request/response:

May 17, 2012 6:33:46 PM com.google.api.client.http.HttpRequest execute
CONFIG: -------------- REQUEST --------------
PUT https://commondatastorage.googleapis.com/*************** Accept-Encoding: gzip
Authorization: Bearer *********************
User-Agent: Google-HTTP-Java-Client/1.8.3-beta (gzip)
x-goog-resumable: start
Content-Type: application/octet-stream
Content-Length: 0

May 17, 2012 6:33:46 PM com.google.api.client.http.HttpResponse
CONFIG: -------------- RESPONSE --------------
HTTP/1.0 411 Length Required
Date: Thu, 17 May 2012 23:33:46 GMT
Content-Length: 934
Content-Type: text/html; charset=UTF-8
Server: GFE/2.0 How would you expect it to be fixed? The problem appears to be in NetHttpRequest which only calls connection.setFixedLengthStreamingMode if contentLength != 0. The comment indicates that it is being guarded to avoid changing a get request to a post request. I've attached a patch that seems to fix the problem.

Attachment: patch.txt

Original issue: http://code.google.com/p/google-http-java-client/issues/detail?id=115

@wonderfly wonderfly added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. imported priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 9, 2015
@wonderfly
Copy link
Contributor Author

From yan...@google.com on July 14, 2012 04:41:01

Status: Accepted
Cc: yan...@google.com
Labels: Milestone-Version1.11.0 Component-HTTP

@wonderfly wonderfly self-assigned this Jan 9, 2015
@wonderfly
Copy link
Contributor Author

From rmis...@google.com on August 16, 2012 09:45:51

http://codereview.appspot.com/6462070/

Status: Started

@wonderfly
Copy link
Contributor Author

@wonderfly
Copy link
Contributor Author

From yan...@google.com on August 22, 2012 13:21:45

Status: Fixed

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 6, 2020
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
Post Release -> 0.7.2-SNAPSHOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants