There's a problem with Connection#url_for. Whenever the buck is implicit in the hostname it cannot be in the url path
as well.
Compare:
http://brettg.s3.amazonaws.com/argle.html
http://brettg.s3.amazonaws.com/brettg/argle.html
The easiest solution I found was for Connection#url_for to check if there is a bucket implicit in the host and if so
just strip any buckets in the given path. This might seem less than ideal because in a perfect world we don't want
Connection#url_for making any assumptions about the paths passed to it (viz. that they all start with a bucket name).
But here's the kicker: for authentication Connection#url_for has to sign the full path including the bucket. So either
Connection#url_for needs two paths passed in or it needs to assume the first part of the path is a bucket. My conscience
is further eased by the fact that all S3 paths do indeed have buckets in them. I would even go so far as to have
Connection#url_for throw an error if the bucket of the path passed to it does not match the bucket implicit in
the hostname.
The patch fixes the issue as discussed above. It also treats buckets that can be inferred from wholly different domain
names the same as buckets inferred from s3.amazonaws.com subdomains (e.g. 'somebucket.com' yields the bucket 'somebucket.com'
just as 'somebucket.s3.amazonaws.com' yields the bucket 'somebucket'). |