Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add support for streaming in getPrivateUrl

  • Loading branch information...
commit 5c43318e8ab6f3c506edcfe81f9cbd7201f8ed37 1 parent b66820e
Christian Tellnes authored

Showing 1 changed file with 21 additions and 6 deletions. Show diff stats Hide diff stats

  1. +21 6 lib/index.js
27 lib/index.js
@@ -425,8 +425,6 @@ CloudFront.prototype.listOriginAccessIdentities = function(opts, cb) {
425 425
426 426 8) options
427 427
428   -
429   - Does not support streaming at the moment.
430 428 */
431 429
432 430 CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
@@ -440,6 +438,7 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
440 438 config.hostname = obj.hostname;
441 439 config.path = obj.path;
442 440 config.secure = obj.protocol === 'https:';
  441 + config.streaming = obj.protocol === 'rtmp:';
443 442 }
444 443
445 444 // args 1 and 2
@@ -501,7 +500,7 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
501 500 throw new TypeError('Missing path argument to CloudFront#getPrivateUrl');
502 501 }
503 502
504   - var resource, policy, signature
  503 + var resource, policy, signature, scheme
505 504 , keyPairId = config.keyPairId || this.keyPairId
506 505 , privateKey = config.privateKey || this.privateKey
507 506 , custom = false
@@ -512,8 +511,18 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
512 511 }
513 512
514 513
  514 + if (config.hostname.substr(-'.cloudfront.net'.length) === '.cloudfront.net') {
  515 + // I can not find this documented, but AWS SDK for PHP does it in this way.
  516 + config.streaming = (config.hostname[0] === 's');
  517 + }
515 518
516   - resource = 'http' + (config.secure ? 's' : '') + '://' + config.hostname + config.path;
  519 + if (config.streaming) {
  520 + scheme = 'rtmp';
  521 + resource = config.path;
  522 + } else {
  523 + scheme = config.secure ? 'https' : 'http';
  524 + resource = scheme + '://' + config.hostname + config.path;
  525 + }
517 526
518 527 policy = {
519 528 "Statement": [{
@@ -557,8 +566,14 @@ CloudFront.prototype.getPrivateUrl = function(a, b, c, d) {
557 566 query["Expires"] = config.expires;
558 567 }
559 568
560   - resource += (~config.path.indexOf('?') ? '&' : '?') + querystring.stringify(query);
561   - return resource;
  569 + return scheme
  570 + + '://'
  571 + + config.hostname
  572 + + config.path
  573 + + (~config.path.indexOf('?') ? '&' : '?')
  574 + + querystring.stringify(query)
  575 + ;
  576 +
562 577 };
563 578
564 579

0 comments on commit 5c43318

Please sign in to comment.
Something went wrong with that request. Please try again.