Permalink
Browse files

[fix] Improve the way CDN urls are handled using auto-magic auth

  • Loading branch information...
1 parent cd51ec5 commit f55835dc53db30d4e6dff4cb02739015e0d7dc78 @indexzero indexzero committed Feb 18, 2011
Showing with 21 additions and 6 deletions.
  1. +17 −4 lib/cloudfiles/core.js
  2. +4 −2 lib/cloudfiles/utils.js
View
21 lib/cloudfiles/core.js
@@ -86,15 +86,28 @@ Cloudfiles.prototype.getContainer = function () {
args = Array.prototype.slice.call(arguments),
callback = (typeof(args[args.length - 1]) === 'function') && args.pop(),
isCdn = args.length > 0 && (typeof(args[args.length - 1]) === 'boolean') && args.pop(),
- containerName = args.pop(),
- url = isCdn ? this.cdnUrl(containerName) : this.storageUrl(containerName);
-
- utils.rackspace('HEAD', url, this, callback, function (body, res) {
+ containerName = args.pop();
+
+ var containerOptions = {
+ method: 'HEAD',
+ uri: isCdn ? this.cdnUrl(containerName) : this.storageUrl(containerName),
+ cdn: isCdn,
+ client: this
+ }
+
+ utils.rackspace(containerOptions, callback, function (body, res) {
var container = {
name: containerName,
count: new Number(res.headers['x-container-object-count']),
bytes: new Number(res.headers['x-container-bytes-used'])
};
+ if (isCdn) {
+ container.cdnUri = res.headers['x-cdn-uri'];
+ container.cdnEnabled = res.headers['x-cdn-enabled'];
+ delete container.count;
+ delete container.bytes;
+ }
+
callback(null, new (cloudfiles.Container)(self, container));
});
};
View
6 lib/cloudfiles/utils.js
@@ -87,7 +87,7 @@ utils.rackspace = function () {
var args = Array.prototype.slice.call(arguments),
success = (typeof(args[args.length - 1]) === 'function') && args.pop(),
callback = (typeof(args[args.length - 1]) === 'function') && args.pop(),
- uri, method, requestBody, responseBodyStream, client, headers = {};
+ uri, method, requestBody, responseBodyStream, client, headers = {}, cdn;
// Now that we've popped off the two callbacks
// We can make decisions about other arguments
@@ -97,6 +97,7 @@ utils.rackspace = function () {
client = args[0]['client'];
requestBody = args[0]['body'];
headers = args[0]['headers'] || {};
+ cdn = args[0]['cdn'] || false;
responseBodyStream = args[0]['responseBodyStream'] || null;
}
else if (args.length === 2) {
@@ -161,7 +162,8 @@ utils.rackspace = function () {
client.setAuth(function (err, res) {
if (err) return callback(err);
- makeRequest(client.storageUrl(uri.slice(1)));
+ uri = uri.slice(1);
+ makeRequest(cdn ? client.cdnUrl(uri) : client.storageUrl(uri));
});
}
};

0 comments on commit f55835d

Please sign in to comment.