artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

PUT + Empty Body tries to send content #220

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client (e.g. 1.5.0-beta)?
1.14.1 beta

Java environment (e.g. Java 6, Android 2.3, App Engine)?
Android 4.2.X (Nexus 4/7)

Describe the problem.
When trying to send a PUT request to express with an empty body (passing null 
for HttpContent) it appears that the request does not EOL so will never finish 
sending data.

I have only tested this with against a node running express 3 end point.

How would you expect it to be fixed?

The request should perform like the generated curl command.

So this code does not work:
HttpRequest request = getHttpRequestFactory()
                .buildPutRequest(new GenericUrl(getURL()), null);

The cURL request this generates does work. Which suggests that this is not a 
server issue but more the client handling Null content incorrectly.

This is the generated cURL:
curl -v --compressed -X PUT -H 'Accept: application/json' -H 'Accept-Encoding: 
gzip' -H 'Content-Type: application/json' -H 'Cookie: 
sid=dfdsfdsfdfsddsfdsfdsf' -H 'connection: close' -- 
http://my.domain.com/some/path/dfdfddfdf

To work around this I had to force an empty object into the content:
final HttpContent content = new JsonHttpContent(getJsonFactory(), new Object());
HttpRequest request = getHttpRequestFactory()
                .buildPutRequest(new GenericUrl(getURL()), content);

Original issue reported on code.google.com by chris.mark.jenkins@gmail.com on 3 May 2013 at 6:25