Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 06, 2012
undid several bugs I introduced into 0.4.0, modified addExtras to all…
…ow for an array of functions, removed the s3 content-length extra (because it didn't do anything), and updated the put-object example to show the proper way to get a string's content-length
restored the extrasContentLength function but made it use Buffer.byte…
…Length() rather than [string].length and made PutBucket call it explicitly rather than it's previous implicit call via extrasContentMd5
Showing with 28 additions and 17 deletions.
  1. +4 −2 examples/amazon/s3/put-object.js
  2. +5 −6 lib/amazon/s3-config.js
  3. +18 −7 lib/awssum.js
  4. +1 −2 test/s3-streaming.js
@@ -16,11 +16,13 @@ console.log( 'AccessKeyId :', s3.accessKeyId() );
// console.log( 'SecretAccessKey :', s3.secretAccessKey() );
console.log( 'AwsAccountId :', s3.awsAccountId() );
+var body = "Hello, World!\n";
+
var options = {
BucketName : 'pie-18',
ObjectName : 'test-object.txt',
- ContentLength : '14',
- Body : "Hello, World!\n",
+ ContentLength : Buffer.byteLength(body), // This is for strings. See put-object-streaming.js for a file example
+ Body : body,
};
s3.PutObject(options, function(err, data) {
View
@@ -299,7 +299,7 @@ function extrasContentLength(options, args) {
var self = this;
// add the Content-Length header we need
- options.headers['Content-Length'] = args.ContentLength || options.body.length;
+ options.headers['Content-Length'] = args.ContentLength || Buffer.byteLength( options.body );
}
function extrasContentMd5(options, args) {
@@ -318,8 +318,6 @@ function extrasContentMd5(options, args) {
else if (args.ContentMD5) {
options.headers['Content-MD5'] = args.ContentMD5;
}
- // add the Content-Length header
- extrasContentLength(options, args)
}
function extrasCopySource(options, args) {
@@ -777,7 +775,7 @@ module.exports = {
},
},
body : bodyLifecycleConfiguration,
- addExtras : extrasContentMd5,
+ addExtras : [ extrasContentMd5, extrasContentLength ],
// response
extractBody : 'none',
},
@@ -1168,12 +1166,13 @@ module.exports = {
required : false,
type : 'header',
},
+ // If you body is a string, run Buffer.byteLength(options.body) to calculate this
ContentLength : {
name : 'Content-Length',
required : true,
type : 'header',
},
- // set by the request after generating the XML
+ // Set automatically unless the body is a ReadableStream.
ContentMD5 : {
name : 'Content-MD5',
required : false,
@@ -1216,7 +1215,7 @@ module.exports = {
type : 'body',
},
},
- addExtras : extrasContentMd5,
+ addExtras : extrasContentMd5,
// response
extractBody : 'none',
},
View
@@ -424,13 +424,19 @@ AwsSum.prototype.send = function(operation, args, callback) {
// add anything extra into the request
var addExtras = operation.addExtras || self.addExtras;
- if ( typeof addExtras === 'function' ) {
- addExtras.apply(self, [ options, args ]);
- }
- else {
- // since this is a program error, we're gonna throw this one
- throw 'Unknown addExtras : ' + typeof addExtras;
+ if ( ! _.isArray(addExtras) ) {
+ addExtras = [addExtras];
}
+ addExtras.forEach( function(extra) {
+ if ( typeof extra === 'function' ) {
+ extra.apply(self, [ options, args ]);
+ }
+ else {
+ // since this is a program error, we're gonna throw this one
+ throw 'Unknown addExtras : ' + typeof extra;
+ }
+ });
+
// finally, add the common operations
self.addCommonOptions(options, args);
@@ -694,6 +700,11 @@ AwsSum.prototype.request = function(options, callback) {
callback(err, null);
});
});
+
+ // if there is an error with the formation of the request, call the callback
+ req.on('error', function(err) {
+ callback(err, null);
+ });
// ---
@@ -704,7 +715,7 @@ AwsSum.prototype.request = function(options, callback) {
}
// if it's a string, send it and end it
- if ( typeof options.body === 'string' ) {
+ if ( typeof options.body === 'string' || options.body instanceof Buffer) {
req.write(options.body);
req.end();
return;
View
@@ -83,8 +83,7 @@ var FAKE_S3_PORT = 3101;
* In order to test with a "real" stream, we're creating a fake client and server. The client
* uploads some data to the server, and the node "req" object passed to the server is a
* ReadableStream containing that data. This ReadableStream is passed directly to
- * AwsSum.prototype.request as the bodyStream param.
- * Note: it should just be named "Body" when passing it to a proper api method like s3.PutObject()
+ * AwsSum.prototype.request as the body.
* This test then sets up a fake s3 server to verify that the request() method properly copied the
* streaming data to the s3 request. Because AweSum only allows for https requests, we've generated
* a fake SSL key pair.

No commit comments for this range