Skip to content
This repository
Browse code

Added support for specifying an HTTP Proxy

  • Loading branch information...
commit 4661cefabca674e54de5d1ca6782000038eb7623 1 parent 522a53e
Cody Caughlan authored September 14, 2011 sikachu committed September 23, 2011
27  lib/paperclip/storage/s3.rb
@@ -95,6 +95,12 @@ def self.extended base
95 95
             @url          = ":s3_path_url"
96 96
           end
97 97
           @url            = ":asset_host" if @options[:url].to_s == ":asset_host"
  98
+          
  99
+          @http_proxy = @options[:http_proxy] || nil
  100
+          if @http_proxy
  101
+            @s3_options.merge!({:proxy => @http_proxy})
  102
+          end
  103
+          
98 104
           AWS::S3::Base.establish_connection!( @s3_options.merge(
99 105
             :access_key_id => @s3_credentials[:access_key_id],
100 106
             :secret_access_key => @s3_credentials[:secret_access_key]
@@ -121,6 +127,27 @@ def expiring_url(time = 3600, style_name = default_style)
121 127
       def bucket_name
122 128
         @bucket
123 129
       end
  130
+      
  131
+      def using_http_proxy?
  132
+        !!@http_proxy
  133
+      end
  134
+      
  135
+      def http_proxy_host
  136
+        using_http_proxy? ? @http_proxy[:host] : nil
  137
+      end
  138
+
  139
+      def http_proxy_port
  140
+        using_http_proxy? ? @http_proxy[:port] : nil
  141
+      end
  142
+      
  143
+      def http_proxy_user
  144
+        using_http_proxy? ? @http_proxy[:user] : nil
  145
+      end
  146
+
  147
+      def http_proxy_password
  148
+        using_http_proxy? ? @http_proxy[:password] : nil
  149
+      end
  150
+      
124 151
 
125 152
       def s3_host_name
126 153
         @s3_host_name || "s3.amazonaws.com"
12  test/storage_test.rb
@@ -41,9 +41,11 @@ def rails_env(env)
41 41
 
42 42
   context "Parsing S3 credentials" do
43 43
     setup do
  44
+      @proxy_settings = {:host => "127.0.0.1", :port => 8888, :user => "foo", :password => "bar"}
44 45
       AWS::S3::Base.stubs(:establish_connection!)
45 46
       rebuild_model :storage => :s3,
46 47
                     :bucket => "testing",
  48
+                    :http_proxy => @proxy_settings,
47 49
                     :s3_credentials => {:not => :important}
48 50
 
49 51
       @dummy = Dummy.new
@@ -68,6 +70,16 @@ def rails_env(env)
68 70
       rails_env("not really an env")
69 71
       assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
70 72
     end
  73
+    
  74
+    should "support HTTP proxy settings" do
  75
+      rails_env("development")
  76
+      assert_equal(true, @avatar.using_http_proxy?)
  77
+      assert_equal(@proxy_settings[:host], @avatar.http_proxy_host)
  78
+      assert_equal(@proxy_settings[:port], @avatar.http_proxy_port)
  79
+      assert_equal(@proxy_settings[:user], @avatar.http_proxy_user)
  80
+      assert_equal(@proxy_settings[:password], @avatar.http_proxy_password)
  81
+    end
  82
+    
71 83
   end
72 84
 
73 85
   context "" do

0 notes on commit 4661cef

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