NetHttpTransport drops Content-Length header when posting 0-length data #115
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.
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
The text was updated successfully, but these errors were encountered: