Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AWS to work in more situations, added a note in the README on its usage #343

Merged
merged 2 commits into from Oct 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -186,6 +186,7 @@ The first argument can be either a url or an options object. The only required o
* `oauth` - Options for OAuth HMAC-SHA1 signing, see documentation above.
* `strictSSL` - Set to `true` to require that SSL certificates be valid. Note: to use your own certificate authority, you need to specify an agent that was created with that ca as an option.
* `jar` - Set to `false` if you don't want cookies to be remembered for future use or define your custom cookie jar (see examples section)
* `aws` - object containing aws signing information, should have the properties `key` and `secret` as well as `bucket` unless you're specifying your bucket as part of the path, or you are making a request that doesn't use a bucket (i.e. GET Services)
The callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second in an http.ClientResponse object. The third is the response body String or Buffer.
Expand Down
17 changes: 13 additions & 4 deletions main.js
Expand Up @@ -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
}
Expand Down