fastimage 1.2.14 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/fastimage.rb +17 -1
  2. data/test/test.rb +12 -0
  3. metadata +2 -2
data/lib/fastimage.rb CHANGED
@@ -206,8 +206,24 @@ class FastImage
206
206
  end
207
207
  end
208
208
 
209
+ def proxy_uri
210
+ begin
211
+ proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? URI.parse(ENV['http_proxy']) : nil
212
+ rescue URI::InvalidURIError
213
+ proxy = nil
214
+ end
215
+ proxy
216
+ end
217
+
209
218
  def setup_http
210
- @http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
219
+ proxy = proxy_uri
220
+
221
+ if proxy
222
+ @http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@parsed_uri.host, @parsed_uri.port)
223
+ else
224
+ @http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
225
+ end
226
+
211
227
  @http.use_ssl = (@parsed_uri.scheme == "https")
212
228
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
213
229
  @http.open_timeout = @timeout
data/test/test.rb CHANGED
@@ -191,4 +191,16 @@ class FastImageTest < Test::Unit::TestCase
191
191
  assert type_time - time < LargeImageFetchLimit
192
192
  assert_equal LargeImageInfo[0], type
193
193
  end
194
+
195
+ # This test doesn't actually test the proxy function, but at least
196
+ # it excercises the code. You could put anything in the http_proxy and it would still pass.
197
+ # Any ideas on how to actually test this?
198
+ def test_should_fetch_via_proxy
199
+ file = "test.gif"
200
+ actual_size = GoodFixtures[file][1]
201
+ ENV['http_proxy'] = "http://my.proxy.host:8080"
202
+ size = FastImage.size(TestUrl + file)
203
+ ENV['http_proxy'] = nil
204
+ assert_equal actual_size, size
205
+ end
194
206
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.14
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-07 00:00:00.000000000 Z
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: FastImage finds the size or type of an image given its uri by fetching
15
15
  as little as needed.