kronk 1.7.8 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,3 +1,35 @@
1
+ === 1.8.0 / 2011-12
2
+
3
+ * Major Enhancements:
4
+
5
+ * Support for TSV player output (read gnuplot).
6
+
7
+ * Removed evented model support; too costly to maintain.
8
+
9
+ * Enhancements:
10
+
11
+ * Parsed Response headers now also return parsed cookies.
12
+
13
+ * Many Player performance improvements.
14
+
15
+ * Player outputs are now Player subclasses.
16
+
17
+ * Support for setting player qps.
18
+
19
+ * Support for response streaming.
20
+
21
+ * Support for gzip and inflate decoding.
22
+
23
+ * Diff accuracy improvements.
24
+
25
+ * Support forwarding HTTP auth information to redirected hosts.
26
+
27
+ * Bugfixes:
28
+
29
+ * Pass request init options to redirects.
30
+
31
+ * QueueRunner multithreading fix for Rubys with no GIL.
32
+
1
33
  === 1.7.8 / 2011-11-10
2
34
 
3
35
  * Enhancements:
data/Manifest.txt CHANGED
@@ -5,10 +5,6 @@ README.rdoc
5
5
  Rakefile
6
6
  bin/kronk
7
7
  lib/kronk.rb
8
- lib/kronk/async.rb
9
- lib/kronk/async/em_ext.rb
10
- lib/kronk/async/request.rb
11
- lib/kronk/async/response.rb
12
8
  lib/kronk/cmd.rb
13
9
  lib/kronk/constants.rb
14
10
  lib/kronk/core_ext.rb
@@ -17,6 +13,8 @@ lib/kronk/diff.rb
17
13
  lib/kronk/diff/ascii_format.rb
18
14
  lib/kronk/diff/color_format.rb
19
15
  lib/kronk/diff/output.rb
16
+ lib/kronk/http.rb
17
+ lib/kronk/buffered_io.rb
20
18
  lib/kronk/path.rb
21
19
  lib/kronk/path/matcher.rb
22
20
  lib/kronk/path/match.rb
@@ -24,10 +22,10 @@ lib/kronk/path/transaction.rb
24
22
  lib/kronk/player.rb
25
23
  lib/kronk/player/benchmark.rb
26
24
  lib/kronk/player/input_reader.rb
27
- lib/kronk/player/output.rb
28
25
  lib/kronk/player/request_parser.rb
29
26
  lib/kronk/player/suite.rb
30
27
  lib/kronk/player/stream.rb
28
+ lib/kronk/player/tsv.rb
31
29
  lib/kronk/plist_parser.rb
32
30
  lib/kronk/queue_runner.rb
33
31
  lib/kronk/request.rb
@@ -38,6 +36,8 @@ lib/kronk/test/helper_methods.rb
38
36
  lib/kronk/xml_parser.rb
39
37
  lib/kronk/yaml_parser.rb
40
38
  script/kronk_completion
39
+ test/mocks/200_gzip.txt
40
+ test/mocks/200_inflate.txt
41
41
  test/mocks/200_response.json
42
42
  test/mocks/200_response.plist
43
43
  test/mocks/200_response.txt
data/README.rdoc CHANGED
@@ -116,13 +116,15 @@ Disabling cookies altogether may be done as so:
116
116
  Setting URI-specific config options - useful if you always need to send
117
117
  headers or use one-off configs. Each URI option key is dropped in a regexp
118
118
  to match against the given URIs so this also works for local files.
119
- See Kronk::Request.retrieve and Kronk::Response#selective_data
119
+ See Kronk::Request.new, Kronk::Response.new and Kronk::Response#data
120
120
  for all options supported:
121
121
 
122
122
  uri_options:
123
123
  example.com:
124
- parser: XMLParser
125
- http_method: POST
124
+ parser: XMLParser
125
+ allow_encoding: gzip;q=1.0
126
+ force_gzip: true
127
+ http_method: POST
126
128
 
127
129
  follow_redirects: true
128
130
 
data/Rakefile CHANGED
@@ -25,10 +25,9 @@ Hoe.spec 'kronk' do
25
25
  self.extra_deps << ['json', '~>1.5']
26
26
  self.extra_deps << ['cookiejar', '~>0.3.0']
27
27
 
28
- self.extra_dev_deps << ['plist', '~>3.1.0']
29
- self.extra_dev_deps << ['nokogiri', '~>1.4']
30
- self.extra_dev_deps << ['mocha', '~>0.9.12']
31
- self.extra_dev_deps << ['em-http-request', '~>1.0.0']
28
+ self.extra_dev_deps << ['plist', '~>3.1.0']
29
+ self.extra_dev_deps << ['nokogiri', '~>1.4']
30
+ self.extra_dev_deps << ['mocha', '~>0.9.12']
32
31
  end
33
32
 
34
33
 
data/TODO.rdoc CHANGED
@@ -1,19 +1,35 @@
1
1
  = TODO
2
2
 
3
- * QPS for player.
3
+ == Maybe Later
4
4
 
5
- * Support for response streaming.
6
-
7
- * Support for X-Url-\d and x-alt-location-\d redirects.
5
+ * Animate Suite player cursor when waiting for input.
8
6
 
9
- * Support for gzip.
7
+ * Consider getting off of net/http.
10
8
 
11
- * Player input IO timeout.
9
+ * Consider allowing Output-specific cmd options.
12
10
 
13
11
  * Investigate Kronk console.
14
12
 
13
+ == Not Viable
14
+
15
+ * Use persistent connection pools.
16
+
15
17
  == Done
16
18
 
19
+ * GNU-Plot support.
20
+
21
+ * Parsed cookie diffing.
22
+
23
+ * Refactor player Output to inherit Player.
24
+
25
+ * Revisit how QueueRunner handles SIGINT.
26
+
27
+ * QPS option for player.
28
+
29
+ * Support for gzip.
30
+
31
+ * Support for response streaming.
32
+
17
33
  * Investigate the use of EM for QueueRunner.
18
34
 
19
35
  * Refactor Kronk::Player into a Player and a QueueRunner.
data/lib/kronk.rb CHANGED
@@ -8,21 +8,22 @@ require 'stringio'
8
8
  require 'base64'
9
9
 
10
10
  require 'net/https'
11
+ require 'zlib'
11
12
  require 'optparse'
12
13
  require 'yaml'
13
14
 
14
15
  class Kronk
15
16
 
16
17
  # This gem's version.
17
- VERSION = '1.7.8'
18
+ VERSION = '1.8.0'
18
19
 
19
20
  require 'kronk/constants'
20
21
  require 'kronk/queue_runner'
21
22
  require 'kronk/player'
22
- require 'kronk/player/output'
23
23
  require 'kronk/player/suite'
24
24
  require 'kronk/player/stream'
25
25
  require 'kronk/player/benchmark'
26
+ require 'kronk/player/tsv'
26
27
  require 'kronk/player/request_parser'
27
28
  require 'kronk/player/input_reader'
28
29
  require 'kronk/cmd'
@@ -35,8 +36,10 @@ class Kronk
35
36
  require 'kronk/diff/color_format'
36
37
  require 'kronk/diff/output'
37
38
  require 'kronk/diff'
38
- require 'kronk/response'
39
+ require 'kronk/http'
40
+ require 'kronk/buffered_io'
39
41
  require 'kronk/request'
42
+ require 'kronk/response'
40
43
  require 'kronk/plist_parser'
41
44
  require 'kronk/xml_parser'
42
45
  require 'kronk/yaml_parser'
@@ -306,6 +309,9 @@ class Kronk
306
309
  str2 = res2.stringify
307
310
  end
308
311
 
312
+ t1.abort_on_exception = true
313
+ t2.abort_on_exception = true
314
+
309
315
  t1.join
310
316
  t2.join
311
317
 
@@ -324,18 +330,18 @@ class Kronk
324
330
  def request uri
325
331
  options = Kronk.config[:no_uri_options] ? @options : options_for_uri(uri)
326
332
 
327
- if IO === uri || StringIO === uri
333
+ if IO === uri || StringIO === uri || BufferedIO === uri
328
334
  Cmd.verbose "Reading IO #{uri}"
329
- resp = Response.new uri
335
+ resp = Response.new uri, options
330
336
 
331
337
  elsif File.file? uri.to_s
332
338
  Cmd.verbose "Reading file: #{uri}\n"
333
- resp = Response.read_file uri
339
+ resp = Response.read_file uri, options
334
340
 
335
341
  else
336
342
  req = Request.new uri, options
337
343
  Cmd.verbose "Retrieving URL: #{req.uri}\n"
338
- resp = req.retrieve
344
+ resp = req.retrieve options
339
345
  Kronk.history << uri
340
346
  end
341
347
 
@@ -0,0 +1,26 @@
1
+ class Kronk
2
+
3
+ ##
4
+ # Wrapper for Net::BufferedIO
5
+
6
+ class BufferedIO < Net::BufferedIO
7
+
8
+ attr_accessor :raw_output
9
+ attr_accessor :response
10
+
11
+ def initialize io
12
+ super
13
+ @raw_output = nil
14
+ @response = nil
15
+ end
16
+
17
+
18
+ private
19
+
20
+ def rbuf_consume len
21
+ str = super
22
+ @raw_output << str if @raw_output
23
+ str
24
+ end
25
+ end
26
+ end
data/lib/kronk/cmd.rb CHANGED
@@ -6,7 +6,7 @@ class Kronk
6
6
  class Cmd
7
7
 
8
8
  RESCUABLE = [
9
- Kronk::Exception, Timeout::Error,
9
+ Kronk::Error, Timeout::Error,
10
10
  SocketError, SystemCallError, URI::InvalidURIError
11
11
  ]
12
12
 
@@ -152,7 +152,7 @@ Parse and run diffs against data from live and cached http responses.
152
152
  end
153
153
 
154
154
 
155
- opt.on('--config STR', String,
155
+ opt.on('--config FILE', String,
156
156
  'Load the given Kronk config file') do |value|
157
157
  Kronk.load_config value
158
158
  end
@@ -170,7 +170,7 @@ Parse and run diffs against data from live and cached http responses.
170
170
 
171
171
 
172
172
  opt.on('--format STR', String,
173
- 'Use a custom diff formatter') do |value|
173
+ 'Use a custom diff formatter class') do |value|
174
174
  Kronk.config[:diff_format] = value
175
175
  end
176
176
 
@@ -180,6 +180,11 @@ Parse and run diffs against data from live and cached http responses.
180
180
  end
181
181
 
182
182
 
183
+ opt.on('--gzip', 'Force decode body with gZip') do
184
+ options[:force_gzip] = true
185
+ end
186
+
187
+
183
188
  opt.on('-i', '--include [HEADER1,HEADER2]', Array,
184
189
  'Include all or given headers in response') do |value|
185
190
  options[:show_headers] ||= []
@@ -215,6 +220,11 @@ Parse and run diffs against data from live and cached http responses.
215
220
  end
216
221
 
217
222
 
223
+ opt.on('--inflate', 'Force decode body with Zlib Inflate') do
224
+ options[:force_inflate] = true
225
+ end
226
+
227
+
218
228
  opt.on('--irb', 'Start an IRB console with the response') do
219
229
  options[:irb] = true
220
230
  end
@@ -246,24 +256,24 @@ Parse and run diffs against data from live and cached http responses.
246
256
  end
247
257
 
248
258
 
249
- opt.on('-R', '--raw', 'Run diff on the raw data returned') do
259
+ opt.on('-R', '--raw', 'Don\'t parse the response') do
250
260
  options[:raw] = true
251
261
  end
252
262
 
253
263
 
254
264
  opt.on('-r', '--require LIB1,LIB2', Array,
255
- 'Require a library or gem') do |value|
265
+ 'Load a file or gem before execution') do |value|
256
266
  options[:requires] ||= []
257
267
  options[:requires].concat value
258
268
  end
259
269
 
260
270
 
261
- opt.on('--ruby', 'Use legacy Ruby renderer') do
271
+ opt.on('--ruby', 'Output Ruby instead of JSON') do
262
272
  Kronk.config[:render_lang] = 'ruby'
263
273
  end
264
274
 
265
275
 
266
- opt.on('--struct', 'Run diff on the data structure') do
276
+ opt.on('--struct', 'Return data types instead of values') do
267
277
  options[:struct] = true
268
278
  end
269
279
 
@@ -279,7 +289,7 @@ Parse and run diffs against data from live and cached http responses.
279
289
  STR
280
290
 
281
291
  opt.on('-c', '--concurrency NUM', Integer,
282
- 'Number of concurrent requests to make; default: 1') do |num|
292
+ 'Number of simultaneous connections; default: 1') do |num|
283
293
  options[:player][:concurrency] = num
284
294
  end
285
295
 
@@ -292,29 +302,41 @@ Parse and run diffs against data from live and cached http responses.
292
302
 
293
303
  opt.on('-o', '--replay-out [FORMAT]',
294
304
  'Output format used by --replay; default: stream') do |output|
295
- options[:player][:output] = output || :stream
305
+ options[:player][:type] = output || :stream
296
306
  end
297
307
 
298
308
 
299
309
  opt.on('-p', '--replay [FILE]',
300
- 'Replay the given file or STDIN against URIs') do |file|
310
+ 'Replay the given file or STDIN against URIs') do |file|
301
311
  options[:player][:io] = File.open(file, "r") if file
302
312
  options[:player][:io] ||= $stdin if !$stdin.tty?
303
- options[:player][:output] ||= :suite
304
313
  end
305
314
 
306
315
 
307
- opt.on('--benchmark [FILE]', 'Same as -p [FILE] -o benchmark') do |file|
316
+ opt.on('--qps NUM', Integer,
317
+ 'Number of queries per second to make; overrides -c') do |num|
318
+ options[:player][:qps] = num
319
+ end
320
+
321
+
322
+ opt.on('--benchmark [FILE]',
323
+ 'Print benchmark data; same as -p [FILE] -o benchmark') do |file|
308
324
  options[:player][:io] = File.open(file, "r") if file
309
- options[:player][:io] ||= $stdin if !$stdin.tty?
310
- options[:player][:output] = :benchmark
325
+ options[:player][:type] = :benchmark
311
326
  end
312
327
 
313
328
 
314
- opt.on('--stream [FILE]', 'Same as -p [FILE] -o stream') do |file|
329
+ opt.on('--stream [FILE]',
330
+ 'Print response stream; same as -p [FILE] -o stream') do |file|
315
331
  options[:player][:io] = File.open(file, "r") if file
316
- options[:player][:io] ||= $stdin if !$stdin.tty?
317
- options[:player][:output] = :stream
332
+ options[:player][:type] = :stream
333
+ end
334
+
335
+
336
+ opt.on('--tsv [FILE]',
337
+ 'Print TSV metrics; same as -p [FILE] -o tsv') do |file|
338
+ options[:player][:io] = File.open(file, "r") if file
339
+ options[:player][:type] = :tsv
318
340
  end
319
341
 
320
342
 
@@ -328,6 +350,12 @@ Parse and run diffs against data from live and cached http responses.
328
350
  end
329
351
 
330
352
 
353
+ opt.on('--compressed',
354
+ 'Request compressed response (using deflate or gzip)') do
355
+ options[:accept_encoding] = %w{gzip;q=1.0 deflate;q=0.6}
356
+ end
357
+
358
+
331
359
  opt.on('-d', '--data STR', String,
332
360
  'Post data with the request') do |value|
333
361
  options[:data] = value
@@ -356,6 +384,13 @@ Parse and run diffs against data from live and cached http responses.
356
384
  end
357
385
 
358
386
 
387
+ opt.on('--location-trusted [NUM]', Integer,
388
+ 'Follow location and send auth to other hosts') do |value|
389
+ options[:trust_location] = true
390
+ options[:follow_redirects] = value || true
391
+ end
392
+
393
+
359
394
  opt.on('--no-cookies', 'Don\'t use cookies for this session') do
360
395
  options[:no_cookies] = true
361
396
  end
@@ -373,7 +408,7 @@ Parse and run diffs against data from live and cached http responses.
373
408
  end
374
409
 
375
410
 
376
- opt.on('-t', '--timeout INT', Integer,
411
+ opt.on('-t', '--timeout NUM', Float,
377
412
  'Timeout for http connection in seconds') do |value|
378
413
  Kronk.config[:timeout] = value
379
414
  end
@@ -398,7 +433,7 @@ Parse and run diffs against data from live and cached http responses.
398
433
 
399
434
 
400
435
  opt.on('-X', '--request STR', String,
401
- 'The request method to use') do |value|
436
+ 'The HTTP request method to use') do |value|
402
437
  options[:http_method] = value
403
438
  end
404
439
 
@@ -414,16 +449,15 @@ Parse and run diffs against data from live and cached http responses.
414
449
  opts.parse! argv
415
450
 
416
451
  unless options[:player].empty?
417
- options[:player] = Player.new options[:player]
418
- set_player_backend Kronk.config[:async]
452
+ options[:player][:io] ||= $stdin if !$stdin.tty?
453
+ player_type = options[:player][:type] || :suite
454
+ options[:player] = Player.new_type player_type, options[:player]
419
455
  else
420
456
  options.delete :player
421
457
  end
422
458
 
423
459
  if !$stdin.tty? && !(options[:player] && options[:player].input.io)
424
- io = $stdin
425
- io = StringIO.new $stdin.read
426
- options[:uris] << io
460
+ options[:uris] << BufferedIO.new($stdin)
427
461
  end
428
462
 
429
463
  options[:uris].concat argv
@@ -616,26 +650,6 @@ Parse and run diffs against data from live and cached http responses.
616
650
  end
617
651
 
618
652
 
619
- ##
620
- # Set Player async state.
621
-
622
- def self.set_player_backend async=false
623
- return Kronk::Player.async = false unless
624
- async == true || async.to_s == 'auto'
625
-
626
- begin
627
- require 'kronk/async'
628
- Kronk::Player.async = true
629
-
630
- rescue LoadError
631
- Kronk::Player.async = false
632
-
633
- raise Kronk::Exception, "Async mode requires the em-http-request gem" if
634
- async == true
635
- end
636
- end
637
-
638
-
639
653
  ##
640
654
  # Assign at_exit and trap :INT behavior.
641
655