From 8874f3a8e65114dba1e1afa374e838fc6418432a Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 27 Jan 2011 19:31:14 -0700 Subject: [PATCH] v0.1.1 --- CHANGELOG | 3 +++ Gemfile.lock | 2 +- lib/slow_web/ext/net_http.rb | 15 +++++++++------ lib/slow_web/version.rb | 2 +- spec/net_http_spec.rb | 9 +++++++++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8e7e2d8..4313c63 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,5 @@ +v0.1.1 +* Fix bug when accessing non-limited hosts. + v0.1.0 * Initial release. diff --git a/Gemfile.lock b/Gemfile.lock index 946c069..48e60a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - slowweb (0.1.0) + slowweb (0.1.1) GEM remote: http://rubygems.org/ diff --git a/lib/slow_web/ext/net_http.rb b/lib/slow_web/ext/net_http.rb index 724d1e8..9902f8c 100644 --- a/lib/slow_web/ext/net_http.rb +++ b/lib/slow_web/ext/net_http.rb @@ -7,13 +7,16 @@ def request_with_slowweb(request, body = nil, &block) host = self.address limit = SlowWeb.get_limit(host) - # Wait until the request limit is no longer exceeded - while limit.exceeded? - sleep 1 - end + # Manage this request if it has been limited + if !limit.nil? + # Wait until the request limit is no longer exceeded + while limit.exceeded? + sleep 1 + end - # Add request to limiter - limit.add_request(request) + # Add request to limiter + limit.add_request(request) + end # Continue with the original request request_without_slowweb(request, body, &block) diff --git a/lib/slow_web/version.rb b/lib/slow_web/version.rb index 763c7f7..2127e92 100644 --- a/lib/slow_web/version.rb +++ b/lib/slow_web/version.rb @@ -1,3 +1,3 @@ class SlowWeb - VERSION = '0.1.0' + VERSION = '0.1.1' end \ No newline at end of file diff --git a/spec/net_http_spec.rb b/spec/net_http_spec.rb index 7ae77dd..0a4cb21 100644 --- a/spec/net_http_spec.rb +++ b/spec/net_http_spec.rb @@ -44,4 +44,13 @@ open('http://github.com') (Time.now-t).should > 1 end + + it 'should ignore unlimited hosts' do + FakeWeb.register_uri(:get, 'http://google.com', :body => 'bar') + SlowWeb.limit('github.com', 3, 60) + open('http://google.com') + open('http://google.com') + open('http://google.com') + open('http://google.com') + end end \ No newline at end of file