Re: 411 Content-Length Required, but Content-Length header is in place (Java)

4,078 views
Skip to first unread message

Corrado

unread,
Jul 9, 2012, 11:32:51 AM7/9/12
to gs-dis...@googlegroups.com
So it looks I found a clue.

Investigating the source code of HttpRequest in google-http-client library, I noticed a small details that made a huge difference. There is this comment

   * Some servers will fail to process a POST/PUT/PATCH unless Content-Length header >= 1. If this
   * value is set to {@code false} then " " is set as the content with Content-Length {@code 1} for
   * empty contents. Defaults to {@code true}.

Wow. To make my PUT bucket request work, I had to write in the request an empty space, with of course Content-Length: 1

And finally, 200 OK.

I suggest the GCS team to put this in evidence in the documentation.

And while I'm here, I would also suggest to take a look at the status codes for responses that have no content. Some endpoints returns a 204 No Content, while others 200 OK but still no content. Consistency would be much appreciated on the developer side.

Thanks, bye!

Erick Fejta

unread,
Jul 11, 2012, 8:14:20 PM7/11/12
to gs-dis...@googlegroups.com
Hi Corrado,

Are you sure that the content-length header is actually getting sent to Google? Some versions of java ignore attempts to manually set certain restricted headers Content-Length is one of these restricted headers.

The following stackoverflow thread explains the situation in detail:


--
You received this message because you are subscribed to the Google Groups "Google Cloud Storage" group.
To view this discussion on the web visit https://groups.google.com/d/msg/gs-discussion/-/mXpqxL8uUHwJ.

To post to this group, send email to gs-dis...@googlegroups.com.
To unsubscribe from this group, send email to gs-discussio...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gs-discussion?hl=en.

Reply all
Reply to author
Forward
0 new messages