On Jun 8, 1:48 pm, Brad Fitzpatrick <
bradf...@golang.org> wrote:
> On Wed, Jun 8, 2011 at 12:30 PM, Russ Ross <
russr...@gmail.com> wrote:
> > I am using an http.Request object to upload a file using the HTTP PUT
> > method. Everything is fine except when attempting to upload a zero-
> > length file. In this case the Content-Length field is omitted from
> > the request, and the server responds with a "411 Length Required"
> > error.
>
> To be clear, this part of your bug report is your webserver's "bug": it's
> speaking a 12 year old version of HTTP and not accepting a chunked encoding
> request body.
The server is Amazon S3, which does state that "Transfer-Encoding:
chunked is not supported". Please forgive my ignorance of HTTP, but I
don't see anything in the headers that indicate a Transfer-Encoding; a
quick glance over http/transfer.go suggested that the Content-Length
field was being removed to accommodate a chunked encoding, but I
didn't knowingly initiate one.
Here is a sample request, produced using req.Write(os.Stdout), edited
to remove <private> data:
PUT /foo.txt HTTP/1.1
Host: <bucketname>.
s3.amazonaws.com
User-Agent: Go http package
Authorization: AWS <request signature>
Content-Type: text/plain
Date: Wed, 08 Jun 2011 14:00:40 MDT
X-Amz-Acl: public-read
X-Amz-Meta-Gid: 1000
X-Amz-Meta-Mode: 0100644
X-Amz-Meta-Mtime: 1307563195.459921506 (Wed Jun 8 13:59:55 MDT 2011)
X-Amz-Meta-Uid: 1000
When I change the file to be of length 1, the only change is the
Content-Length field and the body itself.
I have tried supplying nil as the body of the request (when calling
http.NewRequest), and providing an io.Reader with 0 bytes. The result
is the same in either case.
> > so this case was
> > probably overlooked when testing the library; it seems like a bug to
> > me. Any suggestions for a workaround?
>
> Let me look into it now.
Thank you! If I can provide anything else that would be helpful,
please let me know.