Skip to content
Permalink
Browse files

Content Delivery Network (CDN) - optional, for either uploads only or…

… both uploads & extras (rfe 9134)
  • Loading branch information...
Randall Schwartz
Randall Schwartz committed May 13, 2009
1 parent d6696f8 commit acd3fded451dba51d996edcd504efa51f25785b4
Showing with 646 additions and 11 deletions.
  1. +15 −1 etc/WebGUI.conf.original
  2. +22 −0 lib/WebGUI/Session/Id.pm
  3. +15 −2 lib/WebGUI/Session/Url.pm
  4. +221 −4 lib/WebGUI/Storage.pm
  5. +206 −0 sbin/syncToCdn.pl
  6. +2 −1 t/Session/Id.t
  7. +38 −1 t/Session/Url.t
  8. +127 −2 t/Storage.t
@@ -991,5 +991,19 @@
"WebGUI::Shop::TaxDriver::EU"
],

}
# Content Delivery Network - for use with WebGUI::Storage
# required for CDN: enabled, url, queuePath, syncProgram, deleteProgram
# optional for CDN: sslAlt, sslUrl, extrasCdn, extrasSsl, extrasExclude
"cdn" : { "enabled" : 0,
"url" : "http://content.example.com",
"sslAlt" : 0,
"sslUrl" : "https://ssl.example.com",
"queuePath" : "/data/cdnqueue",
"syncProgram" : "/usr/bin/rsync -av --chmod=u+rwx -- '%s' user@content.example.com:/path",
"deleteProgram" : "/usr/bin/ssh user@content.example.com 'rm -Rf -- %s'"
"extrasCdn" : "http://content.example.com/extras",
"extrasSsl" : "https://content.example.com/extras",
"extrasExclude": ["tinymce", "^blah$"]
}

}
@@ -42,6 +42,28 @@ These methods are available from this class:
=cut


#-------------------------------------------------------------------

=head2 fromHex ( hexId )
Returns the guid corresponding to hexId. Converse of toHex.
=head3 hexId
Hex value to convert to guid.
=cut

sub fromHex {
my $self = shift;
my $hexId = shift;
my $binId = pack('H2' x 16, unpack('A2' x 16, $hexId));
my $id = substr(encode_base64($binId), 0, 22);
$id =~ tr{+/}{_-};
return $id;
}

#-------------------------------------------------------------------

=head2 DESTROY ( )
@@ -131,7 +131,7 @@ sub escape {

=head2 extras ( path )
Combinds the base extrasURL defined in the config file with a specfied path.
Combines the base extrasURL defined in the config file with a specified path.
=head3 path
@@ -144,7 +144,20 @@ consecutive slashes in the path part of the URL will be replaced with a single s
sub extras {
my $self = shift;
my $path = shift;
my $url = $self->session->config->get("extrasURL").'/'.$path;
my $url = $self->session->config->get("extrasURL");
my $cdnCfg = $self->session->config->get('cdn');
if ($cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'extrasCdn'}) {
unless ($path and grep $path =~ m/$_/, @{$cdnCfg->{'extrasExclude'}}) {
if ($cdnCfg->{'extrasSsl'} and
($self->session->env->get('HTTPS') eq 'on' or
$self->session->env->get('SSLPROXY'))) {
$url = $cdnCfg->{'extrasSsl'};
} else {
$url = $cdnCfg->{'extrasCdn'};
}
} # if excluded, stick with regular extrasURL
}
$url .= '/' . $path;
$url =~ s$(?<!:)/{2,}$/$g; ##Remove //, unless it's after a :, which can't be a valid URL character
return $url;
}

0 comments on commit acd3fde

Please sign in to comment.
You can’t perform that action at this time.