Permalink
Browse files

[feature] chunked-encoding for streams without length

  • Loading branch information...
1 parent ef476af commit 130196b2e1f936171833149a800081ef888ce9a1 @bmeck bmeck committed Dec 21, 2011
Showing with 36 additions and 5 deletions.
  1. +1 −1 lib/cloudfiles/common.js
  2. +11 −1 lib/cloudfiles/core.js
  3. +4 −1 test/authentication-test.js
  4. +3 −2 test/container-test.js
  5. +17 −0 test/storage-object-test.js
View
2 lib/cloudfiles/common.js
@@ -166,7 +166,7 @@ common.rackspace = function () {
if (upload) {
if (!options.headers['content-length']) {
- return callback(new Error('Cannot upload file without `content-length` header'));
+ options.headers['transfer-encoding'] = 'chunked';
}
}
View
12 lib/cloudfiles/core.js
@@ -343,11 +343,21 @@ Cloudfiles.prototype.getFile = function (container, filename, callback) {
});
};
+//
+// options
+// remote
+// local
+// stream
+// mime
+//
Cloudfiles.prototype.addFile = function (container, options, callback) {
if (typeof options === 'function' && !callback) {
callback = options;
options = {};
}
+ if (!options.remote) {
+ return callback(new Error('.remote is required to addFile'));
+ }
var lstream,
addOptions,
@@ -363,7 +373,7 @@ Cloudfiles.prototype.addFile = function (container, options, callback) {
}
if (!lstream) {
- return callback(new Error('.local or .stream is required to addFile.'))
+ return callback(new Error('.local or .stream is required to addFile.'));
}
addOptions = {
View
5 test/authentication-test.js
@@ -12,15 +12,17 @@ var path = require('path'),
helpers = require('./helpers'),
cloudfiles = require('../lib/cloudfiles');
-var client = helpers.createClient();
+var client = helpers.createClient();
+
vows.describe('node-cloudfiles/authentication').addBatch({
"The node-cloudfiles client": {
"with a valid username and api key": {
topic: function () {
client.setAuth(this.callback);
},
"should respond with 204 and appropriate headers": function (err, res) {
+ assert.isNull(err);
assert.equal(res.statusCode, 204);
assert.isObject(res.headers);
assert.include(res.headers, 'x-server-management-url');
@@ -29,6 +31,7 @@ vows.describe('node-cloudfiles/authentication').addBatch({
assert.include(res.headers, 'x-auth-token');
},
"should update the config with appropriate urls": function (err, res) {
+ assert.isNull(err);
assert.equal(res.headers['x-server-management-url'], client.config.serverUrl);
assert.equal(res.headers['x-storage-url'], client.config.storageUrl);
assert.equal(res.headers['x-cdn-management-url'], client.config.cdnUrl);
View
5 test/container-test.js
@@ -118,8 +118,9 @@ vows.describe('node-cloudfiles/containers').addBatch({
remote: 'file1.txt',
local: path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt')
}, function () { });
-
- ustream.on('end', this.callback)
+ if (ustream) {
+ ustream.on('end', this.callback)
+ }
},
"should raise the `end` event": function () {
assert.isTrue(true);
View
17 test/storage-object-test.js
@@ -68,6 +68,23 @@ vows.describe('node-cloudfiles/storage-object').addBatch(helpers.requireAuth(cli
"should raise the `end` event": function () {
assert.isTrue(true);
}
+ },
+ "the addFile() method using a stream without a predefined length": {
+ topic: function () {
+ var fileName = path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt'),
+ readStream = fs.createReadStream(fileName),
+ ustream;
+
+ ustream = client.addFile('test_container', {
+ remote: 'file3.txt',
+ stream: readStream
+ }, this.callback);
+
+ ustream.on('end', this.callback);
+ },
+ "should raise the `end` event": function () {
+ assert.isTrue(true);
+ }
}
}
}).addBatch({

0 comments on commit 130196b

Please sign in to comment.