kronk 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.2.4 / 2011-03-04
2
+
3
+ * Enhancements:
4
+
5
+ * Cleaner exit on sigint.
6
+
7
+ * Support for connection timeout in both config and uri options.
8
+
1
9
  === 1.2.3 / 2011-02-20
2
10
 
3
11
  * Bugfixes:
data/lib/kronk.rb CHANGED
@@ -11,7 +11,7 @@ require 'yaml'
11
11
  class Kronk
12
12
 
13
13
  # This gem's version.
14
- VERSION = '1.2.3'
14
+ VERSION = '1.2.4'
15
15
 
16
16
 
17
17
  ##
@@ -85,15 +85,15 @@ class Kronk
85
85
  # Default config to use.
86
86
  DEFAULT_CONFIG = {
87
87
  :content_types => DEFAULT_CONTENT_TYPES.dup,
88
- :default_host => "http://localhost:3000",
89
- :diff_format => :ascii_diff,
90
- :show_lines => false,
91
88
  :cache_file => DEFAULT_CACHE_FILE,
92
89
  :cookies_file => DEFAULT_COOKIES_FILE,
90
+ :default_host => "http://localhost:3000",
91
+ :diff_format => :ascii_diff,
93
92
  :history_file => DEFAULT_HISTORY_FILE,
94
- :use_cookies => true,
95
93
  :requires => [],
94
+ :show_lines => false,
96
95
  :uri_options => {},
96
+ :use_cookies => true,
97
97
  :user_agents => USER_AGENTS.dup
98
98
  }
99
99
 
@@ -428,6 +428,11 @@ class Kronk
428
428
  save_history
429
429
  end
430
430
 
431
+ trap 'INT' do
432
+ exit 2
433
+ end
434
+
435
+
431
436
  options[:cache_response] = config[:cache_file] if config[:cache_file]
432
437
 
433
438
  uri1, uri2 = options.delete :uris
@@ -448,7 +453,7 @@ class Kronk
448
453
  puts out
449
454
  end
450
455
 
451
- rescue Request::NotFoundError, Response::MissingParser => e
456
+ rescue Request::Exception, Response::MissingParser => e
452
457
  $stderr << "\nError: #{e.message}\n"
453
458
  exit 2
454
459
  end
@@ -671,6 +676,12 @@ Parse and run diffs against data from live and cached http responses.
671
676
  end
672
677
 
673
678
 
679
+ opt.on('--timeout INT', Integer,
680
+ 'Timeout for http connection in seconds') do |value|
681
+ config[:timeout] = value
682
+ end
683
+
684
+
674
685
  opt.on('-U', '--proxy-user STR', String,
675
686
  'Set proxy user and/or password: usr[:pass]') do |value|
676
687
  options[:proxy][:username], options[:proxy][:password] =
data/lib/kronk/request.rb CHANGED
@@ -5,10 +5,15 @@ class Kronk
5
5
 
6
6
  class Request
7
7
 
8
+ # Generic Request exception.
9
+ class Exception < ::Exception; end
8
10
 
9
11
  # Raised when the URI was not resolvable.
10
12
  class NotFoundError < Exception; end
11
13
 
14
+ # Raised when HTTP times out.
15
+ class TimeoutError < Exception; end
16
+
12
17
  ##
13
18
  # Follows the redirect from a 30X response object and decrease the
14
19
  # number of redirects left if it's an Integer.
@@ -66,8 +71,12 @@ class Kronk
66
71
  end
67
72
 
68
73
  resp
74
+
69
75
  rescue SocketError, Errno::ENOENT, Errno::ECONNREFUSED
70
76
  raise NotFoundError, "#{uri} could not be found"
77
+
78
+ rescue Timeout::Error
79
+ raise TimeoutError, "#{uri} took too long to respond"
71
80
  end
72
81
 
73
82
 
@@ -197,6 +206,9 @@ class Kronk
197
206
  req = http_class.new uri.host, uri.port
198
207
  req.use_ssl = true if uri.scheme =~ /^https$/
199
208
 
209
+ options[:timeout] ||= Kronk.config[:timeout]
210
+ req.read_timeout = options[:timeout] if options[:timeout]
211
+
200
212
  resp = req.start do |http|
201
213
  socket = http.instance_variable_get "@socket"
202
214
  socket.debug_output = socket_io = StringIO.new
data/test/test_request.rb CHANGED
@@ -116,7 +116,8 @@ class TestRequest < Test::Unit::TestCase
116
116
 
117
117
  Kronk::Request.expects(:follow_redirect).
118
118
  with resp, :follow_redirects => true,
119
- :headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']}
119
+ :headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']},
120
+ :timeout => nil
120
121
 
121
122
  Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar",
122
123
  :follow_redirects => true
@@ -129,7 +130,8 @@ class TestRequest < Test::Unit::TestCase
129
130
 
130
131
  Kronk::Request.expects(:follow_redirect).
131
132
  with resp, :follow_redirects => 3, :data => {:foo => "bar"},
132
- :headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']}
133
+ :headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']},
134
+ :timeout => nil
133
135
 
134
136
  Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar",
135
137
  :follow_redirects => 3, :data => {:foo => "bar"}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kronk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 3
10
- version: 1.2.3
9
+ - 4
10
+ version: 1.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremie Castagna
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-22 00:00:00 -08:00
18
+ date: 2011-03-04 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency