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

Comments

@wonderfly
Copy link
Contributor

@wonderfly wonderfly commented Jan 9, 2015

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

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

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

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

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

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

Status: Started

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

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

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.