Skip to content

Commit

Permalink
add support for streaming in getPrivateUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
tellnes committed Apr 26, 2012
1 parent b66820e commit 5c43318
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ CloudFront.prototype.listOriginAccessIdentities = function(opts, cb) {
8) options
Does not support streaming at the moment.
*/

CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
Expand All @@ -440,6 +438,7 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
config.hostname = obj.hostname;
config.path = obj.path;
config.secure = obj.protocol === 'https:';
config.streaming = obj.protocol === 'rtmp:';
}

// args 1 and 2
Expand Down Expand Up @@ -501,7 +500,7 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
throw new TypeError('Missing path argument to CloudFront#getPrivateUrl');
}

var resource, policy, signature
var resource, policy, signature, scheme
, keyPairId = config.keyPairId || this.keyPairId
, privateKey = config.privateKey || this.privateKey
, custom = false
Expand All @@ -512,8 +511,18 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
}


if (config.hostname.substr(-'.cloudfront.net'.length) === '.cloudfront.net') {
// I can not find this documented, but AWS SDK for PHP does it in this way.
config.streaming = (config.hostname[0] === 's');
}

resource = 'http' + (config.secure ? 's' : '') + '://' + config.hostname + config.path;
if (config.streaming) {
scheme = 'rtmp';
resource = config.path;
} else {
scheme = config.secure ? 'https' : 'http';
resource = scheme + '://' + config.hostname + config.path;
}

policy = {
"Statement": [{
Expand Down Expand Up @@ -557,8 +566,14 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
query["Expires"] = config.expires;
}

resource += (~config.path.indexOf('?') ? '&' : '?') + querystring.stringify(query);
return resource;
return scheme
+ '://'
+ config.hostname
+ config.path
+ (~config.path.indexOf('?') ? '&' : '?')
+ querystring.stringify(query)
;

};


Expand Down

0 comments on commit 5c43318

Please sign in to comment.