Skip to content

Commit

Permalink
Allow for an optional "cloud_files_cdn_host"
Browse files Browse the repository at this point in the history
configuration variable that drastically speeds
up use of Rackspace Cloud Files.

Also, reparing an issue with URL matchers. Rackspace
changed some of their layout and that broke the
tests. "cdn1" vs "cdn" vs "cdn2" in the host name.
  • Loading branch information
HamptonMakes authored and jnicklas committed Jul 20, 2010
1 parent e6a6daa commit 21fd8b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
15 changes: 9 additions & 6 deletions lib/carrierwave/storage/cloud_files.rb
Expand Up @@ -15,12 +15,11 @@ module Storage
# config.cloud_files_container = "my_container"
# end
#
# You can optionally include the configuration (with your CDN host name).
# This is *highly* recommended, as without it every request requires a lookup
# of this information.
#
# You can set the access policy for the uploaded files:
#
# CarrierWave.configure do |config|
# config.s3_access_policy = 'public-read'
# end
# config.cloud_files_cdn_host = "c000000.cdn.rackspacecloud.com"
#
#
class CloudFiles < Abstract
Expand Down Expand Up @@ -73,7 +72,11 @@ def delete
# [String] file's url
#
def url
cf_container.object(@path).public_url
if @uploader.cloud_files_cdn_host
"http://" + @uploader.cloud_files_cdn_host + "/" + @path
else
cf_container.object(@path).public_url
end
end

#def metadata
Expand Down
1 change: 1 addition & 0 deletions lib/carrierwave/uploader/configuration.rb
Expand Up @@ -17,6 +17,7 @@ module Configuration
add_config :cloud_files_username
add_config :cloud_files_api_key
add_config :cloud_files_container
add_config :cloud_files_cdn_host
add_config :grid_fs_database
add_config :grid_fs_host
add_config :grid_fs_port
Expand Down
16 changes: 13 additions & 3 deletions spec/storage/cloudfiles_spec.rb
Expand Up @@ -12,6 +12,7 @@
@uploader.stub!(:cloud_files_username).and_return(ENV["CLOUD_FILES_USER_NAME"])
@uploader.stub!(:cloud_files_api_key).and_return(ENV["CLOUD_FILES_API_KEY"])
@uploader.stub!(:cloud_files_container).and_return(ENV['CARRIERWAVE_TEST_CONTAINER'])
@uploader.stub!(:cloud_files_cdn_host).and_return(nil) # Unless configured below
@storage = CarrierWave::Storage::CloudFiles.new(@uploader)
@file = stub_tempfile('test.jpg', 'application/xml')

Expand All @@ -34,11 +35,13 @@
end

it "should have an Rackspace URL" do
@cloud_file.url.should =~ %r!http://(.*?).cdn.cloudfiles.rackspacecloud.com/uploads/bar.txt!
# Don't check if its ".cdn." or ".cdn2." because they change these URLs
@cloud_file.url.should =~ %r!http://(.*?).rackspacecloud.com/uploads/bar.txt!
end

it "should store the content type on Cloud Files" do
@cloud_file.content_type.should == 'application/xml'
# Recent addition of the charset to the response
@cloud_file.content_type.should == 'application/xml; charset=UTF-8'
end

it "should be deletable" do
Expand All @@ -65,14 +68,21 @@
end

it "should have an Rackspace URL" do
@cloud_file.url.should =~ %r!http://(.*?).cdn.cloudfiles.rackspacecloud.com/uploads/bar.txt!
# Don't check if its ".cdn." or ".cdn2." because they change these URLs
@cloud_file.url.should =~ %r!http://(.*?).rackspacecloud.com/uploads/bar.txt!
end

it "should allow for configured CDN urls" do
@uploader.stub!(:cloud_files_cdn_host).and_return("cdn.com")
@cloud_file.url.should == 'http://cdn.com/uploads/bar.txt'
end

it "should be deletable" do
@cloud_file.delete
@container.object_exists?('uploads/bar.txt').should be_false
end
end


end
end

0 comments on commit 21fd8b9

Please sign in to comment.