Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Added support for specifying an HTTP Proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ruckus authored and sikachu committed Sep 23, 2011
1 parent 522a53e commit 4661cef
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/paperclip/storage/s3.rb
Expand Up @@ -95,6 +95,12 @@ def self.extended base
@url = ":s3_path_url" @url = ":s3_path_url"
end end
@url = ":asset_host" if @options[:url].to_s == ":asset_host" @url = ":asset_host" if @options[:url].to_s == ":asset_host"

@http_proxy = @options[:http_proxy] || nil
if @http_proxy
@s3_options.merge!({:proxy => @http_proxy})
end

AWS::S3::Base.establish_connection!( @s3_options.merge( AWS::S3::Base.establish_connection!( @s3_options.merge(
:access_key_id => @s3_credentials[:access_key_id], :access_key_id => @s3_credentials[:access_key_id],
:secret_access_key => @s3_credentials[:secret_access_key] :secret_access_key => @s3_credentials[:secret_access_key]
Expand All @@ -121,6 +127,27 @@ def expiring_url(time = 3600, style_name = default_style)
def bucket_name def bucket_name
@bucket @bucket
end end

def using_http_proxy?
!!@http_proxy
end

def http_proxy_host
using_http_proxy? ? @http_proxy[:host] : nil
end

def http_proxy_port
using_http_proxy? ? @http_proxy[:port] : nil
end

def http_proxy_user
using_http_proxy? ? @http_proxy[:user] : nil
end

def http_proxy_password
using_http_proxy? ? @http_proxy[:password] : nil
end



def s3_host_name def s3_host_name
@s3_host_name || "s3.amazonaws.com" @s3_host_name || "s3.amazonaws.com"
Expand Down
12 changes: 12 additions & 0 deletions test/storage_test.rb
Expand Up @@ -41,9 +41,11 @@ def rails_env(env)


context "Parsing S3 credentials" do context "Parsing S3 credentials" do
setup do setup do
@proxy_settings = {:host => "127.0.0.1", :port => 8888, :user => "foo", :password => "bar"}
AWS::S3::Base.stubs(:establish_connection!) AWS::S3::Base.stubs(:establish_connection!)
rebuild_model :storage => :s3, rebuild_model :storage => :s3,
:bucket => "testing", :bucket => "testing",
:http_proxy => @proxy_settings,
:s3_credentials => {:not => :important} :s3_credentials => {:not => :important}


@dummy = Dummy.new @dummy = Dummy.new
Expand All @@ -68,6 +70,16 @@ def rails_env(env)
rails_env("not really an env") rails_env("not really an env")
assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345")) assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
end end

should "support HTTP proxy settings" do
rails_env("development")
assert_equal(true, @avatar.using_http_proxy?)
assert_equal(@proxy_settings[:host], @avatar.http_proxy_host)
assert_equal(@proxy_settings[:port], @avatar.http_proxy_port)
assert_equal(@proxy_settings[:user], @avatar.http_proxy_user)
assert_equal(@proxy_settings[:password], @avatar.http_proxy_password)
end

end end


context "" do context "" do
Expand Down

0 comments on commit 4661cef

Please sign in to comment.