Permalink
Browse files

fixup aws function to work in more situations

  • Loading branch information...
1 parent e82dd8a commit f6bcf3eb51982180e813c69cccb942734f815ffe @nlf nlf committed Oct 12, 2012
Showing with 13 additions and 4 deletions.
  1. +13 −4 main.js
View
17 main.js
@@ -806,17 +806,26 @@ Request.prototype.aws = function (opts, now) {
}
var date = new Date()
this.setHeader('date', date.toUTCString())
- this.setHeader('authorization', aws.authorization(
+ var auth =
{ key: opts.key
, secret: opts.secret
- , verb: this.method
+ , verb: this.method.toUpperCase()
, date: date
- , resource: aws.canonicalizeResource('/' + opts.bucket + this.path)
, contentType: this.headers['content-type'] || ''
, md5: this.headers['content-md5'] || ''
, amazonHeaders: aws.canonicalizeHeaders(this.headers)
}
- ))
+ if (opts.bucket && this.path) {
+ auth.resource = '/' + opts.bucket + this.path
+ } else if (opts.bucket && !this.path) {
+ auth.resource = '/' + opts.bucket
+ } else if (!opts.bucket && this.path) {
+ auth.resource = this.path
+ } else if (!opts.bucket && !this.path) {
+ auth.resource = '/'
+ }
+ auth.resource = aws.canonicalizeResource(auth.resource)
+ this.setHeader('authorization', aws.authorization(auth))
return this
}

0 comments on commit f6bcf3e

Please sign in to comment.