kronk 1.8.7 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +22 -0
- data/Manifest.txt +6 -1
- data/README.rdoc +7 -2
- data/Rakefile +5 -4
- data/TODO.rdoc +3 -5
- data/lib/kronk.rb +20 -14
- data/lib/kronk/buffered_io.rb +7 -0
- data/lib/kronk/cmd.rb +25 -9
- data/lib/kronk/constants.rb +8 -0
- data/lib/kronk/http.rb +129 -2
- data/lib/kronk/multipart.rb +82 -0
- data/lib/kronk/multipart_io.rb +88 -0
- data/lib/kronk/player.rb +1 -1
- data/lib/kronk/player/benchmark.rb +69 -24
- data/lib/kronk/player/download.rb +87 -0
- data/lib/kronk/player/suite.rb +23 -11
- data/lib/kronk/request.rb +144 -77
- data/lib/kronk/response.rb +55 -18
- data/test/mocks/200_response.plist +1 -1
- data/test/test_cmd.rb +5 -3
- data/test/test_helper.rb +20 -10
- data/test/test_multipart.rb +144 -0
- data/test/test_multipart_io.rb +92 -0
- data/test/test_player.rb +7 -2
- data/test/test_request.rb +160 -43
- data/test/test_response.rb +34 -2
- metadata +27 -4
data/test/test_player.rb
CHANGED
@@ -384,8 +384,13 @@ class TestPlayer < Test::Unit::TestCase
|
|
384
384
|
req1 = Kronk::Request.new "example.com"
|
385
385
|
req2 = Kronk::Request.new "beta-example.com"
|
386
386
|
|
387
|
-
Kronk::Request.expects(:new).
|
388
|
-
|
387
|
+
Kronk::Request.expects(:new).
|
388
|
+
with("example.com", :uri_suffix => '/test', :include_headers => true).
|
389
|
+
returns req1
|
390
|
+
|
391
|
+
Kronk::Request.expects(:new).
|
392
|
+
with("beta-example.com", :uri_suffix => '/test', :include_headers => true).
|
393
|
+
returns req2
|
389
394
|
|
390
395
|
req1.expects(:retrieve).returns resp1
|
391
396
|
req2.expects(:retrieve).returns resp2
|
data/test/test_request.rb
CHANGED
@@ -77,7 +77,7 @@ class TestRequest < Test::Unit::TestCase
|
|
77
77
|
def test_retrieve_post
|
78
78
|
expect_request "POST", "http://example.com/request/path?foo=bar",
|
79
79
|
:data => {'test' => 'thing'},
|
80
|
-
:headers => {'X-THING' => 'thing'
|
80
|
+
:headers => {'X-THING' => 'thing'}
|
81
81
|
|
82
82
|
resp = Kronk::Request.new("http://example.com/request/path?foo=bar",
|
83
83
|
:data => 'test=thing', :headers => {'X-THING' => 'thing'},
|
@@ -154,11 +154,11 @@ class TestRequest < Test::Unit::TestCase
|
|
154
154
|
req = Kronk::Request.new "foo.com"
|
155
155
|
req.headers['Transfer-Encoding'] = "chunked"
|
156
156
|
req.body = {:foo => :bar}
|
157
|
+
req = req.http_request
|
157
158
|
|
158
159
|
assert_equal "foo=bar", req.body
|
159
|
-
assert_equal
|
160
|
-
assert_equal "application/x-www-form-urlencoded",
|
161
|
-
req.headers['Content-Type']
|
160
|
+
assert_equal 'chunked', req['Transfer-Encoding']
|
161
|
+
assert_equal "application/x-www-form-urlencoded", req['Content-Type']
|
162
162
|
end
|
163
163
|
|
164
164
|
|
@@ -166,23 +166,37 @@ class TestRequest < Test::Unit::TestCase
|
|
166
166
|
req = Kronk::Request.new "foo.com", :form => "blah"
|
167
167
|
req.headers['Transfer-Encoding'] = "chunked"
|
168
168
|
req.body = "foo=bar"
|
169
|
+
req = req.http_request
|
169
170
|
|
170
171
|
assert_equal "foo=bar", req.body
|
171
|
-
assert_equal
|
172
|
-
assert_equal '7', req
|
173
|
-
assert_equal "application/x-www-form-urlencoded",
|
174
|
-
req.headers['Content-Type']
|
172
|
+
assert_equal 'chunked', req['Transfer-Encoding']
|
173
|
+
assert_equal '7', req['Content-Length']
|
174
|
+
assert_equal "application/x-www-form-urlencoded", req['Content-Type']
|
175
175
|
end
|
176
176
|
|
177
177
|
|
178
178
|
def test_body_string_io
|
179
179
|
req = Kronk::Request.new "foo.com"
|
180
180
|
req.body = str_io = StringIO.new("foo=bar")
|
181
|
+
req = req.http_request
|
181
182
|
|
182
|
-
assert_equal str_io, req.
|
183
|
-
assert_equal nil, req
|
184
|
-
assert_equal 'application/binary', req
|
185
|
-
assert_equal '7', req
|
183
|
+
assert_equal str_io, req.body_stream
|
184
|
+
assert_equal nil, req['Transfer-Encoding']
|
185
|
+
assert_equal 'application/binary', req['Content-Type']
|
186
|
+
assert_equal '7', req['Content-Length']
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def test_body_nil
|
191
|
+
req = Kronk::Request.new "foo.com"
|
192
|
+
req.body = nil
|
193
|
+
req = req.http_request
|
194
|
+
|
195
|
+
assert_equal nil, req.body_stream
|
196
|
+
assert_equal "", req.body
|
197
|
+
assert_equal nil, req['Transfer-Encoding']
|
198
|
+
assert_equal nil, req['Content-Type']
|
199
|
+
assert_equal '0', req['Content-Length']
|
186
200
|
end
|
187
201
|
|
188
202
|
|
@@ -190,23 +204,25 @@ class TestRequest < Test::Unit::TestCase
|
|
190
204
|
req = Kronk::Request.new "foo.com"
|
191
205
|
io, = IO.pipe
|
192
206
|
req.body = io
|
207
|
+
req = req.http_request
|
193
208
|
|
194
|
-
assert_equal io, req.
|
195
|
-
assert_equal 'chunked', req
|
196
|
-
assert_equal 'application/binary', req
|
197
|
-
assert_equal nil, req
|
209
|
+
assert_equal io, req.body_stream
|
210
|
+
assert_equal 'chunked', req['Transfer-Encoding']
|
211
|
+
assert_equal 'application/binary', req['Content-Type']
|
212
|
+
assert_equal nil, req['Content-Length']
|
198
213
|
end
|
199
214
|
|
200
215
|
|
201
216
|
def test_body_file_io
|
202
|
-
io = File.open '
|
217
|
+
io = File.open 'Manifest.txt', 'r'
|
203
218
|
req = Kronk::Request.new "foo.com"
|
204
219
|
req.body = io
|
220
|
+
req = req.http_request
|
205
221
|
|
206
|
-
assert_equal io,
|
207
|
-
assert_equal nil,
|
208
|
-
assert_equal '
|
209
|
-
assert_equal io.size.to_s,
|
222
|
+
assert_equal io, req.body_stream
|
223
|
+
assert_equal nil, req['Transfer-Encoding']
|
224
|
+
assert_equal 'text/plain', req['Content-Type']
|
225
|
+
assert_equal io.size.to_s, req['Content-Length']
|
210
226
|
|
211
227
|
ensure
|
212
228
|
io.close
|
@@ -217,10 +233,11 @@ class TestRequest < Test::Unit::TestCase
|
|
217
233
|
req = Kronk::Request.new "foo.com"
|
218
234
|
req.headers['Transfer-Encoding'] = "chunked"
|
219
235
|
req.body = 12345
|
236
|
+
req = req.http_request
|
220
237
|
|
221
|
-
assert_equal "12345",
|
222
|
-
assert_equal
|
223
|
-
assert_equal nil,
|
238
|
+
assert_equal "12345", req.body
|
239
|
+
assert_equal "chunked", req['Transfer-Encoding']
|
240
|
+
assert_equal nil, req['Content-Type']
|
224
241
|
end
|
225
242
|
|
226
243
|
|
@@ -392,9 +409,7 @@ class TestRequest < Test::Unit::TestCase
|
|
392
409
|
|
393
410
|
|
394
411
|
def test_retrieve_ssl
|
395
|
-
expect_request "GET", "https://example.com"
|
396
|
-
req.expects(:use_ssl=).with true
|
397
|
-
end
|
412
|
+
expect_request "GET", "https://example.com", :ssl => true
|
398
413
|
|
399
414
|
resp = Kronk::Request.new("https://example.com").retrieve
|
400
415
|
|
@@ -479,10 +494,7 @@ class TestRequest < Test::Unit::TestCase
|
|
479
494
|
:password => "smith"
|
480
495
|
}
|
481
496
|
|
482
|
-
expect_request "GET", "http://example.com"
|
483
|
-
|
484
|
-
Kronk::HTTP.expects(:Proxy).with("proxy.com", 8080, "john", "smith").
|
485
|
-
returns Kronk::HTTP
|
497
|
+
expect_request "GET", "http://example.com", :proxy => proxy
|
486
498
|
|
487
499
|
Kronk::Request.new("http://example.com", :proxy => proxy).retrieve
|
488
500
|
end
|
@@ -491,22 +503,16 @@ class TestRequest < Test::Unit::TestCase
|
|
491
503
|
def test_retrieve_proxy_string
|
492
504
|
proxy = "proxy.com:8888"
|
493
505
|
|
494
|
-
expect_request "GET", "http://example.com"
|
495
|
-
|
496
|
-
Kronk::HTTP.expects(:Proxy).with("proxy.com", "8888", nil, nil).
|
497
|
-
returns Kronk::HTTP
|
506
|
+
expect_request "GET", "http://example.com",
|
507
|
+
:proxy => {:host => 'proxy.com', :port => "8888"}
|
498
508
|
|
499
509
|
Kronk::Request.new("http://example.com", :proxy => proxy).retrieve
|
500
510
|
end
|
501
511
|
|
502
512
|
|
503
|
-
def test_proxy_nil
|
504
|
-
assert_equal Kronk::HTTP, Kronk::Request.new("host.com").http_proxy(nil)
|
505
|
-
end
|
506
|
-
|
507
|
-
|
508
513
|
def test_proxy_string
|
509
|
-
proxy_class = Kronk::Request.new("host.com"
|
514
|
+
proxy_class = Kronk::Request.new("host.com", :proxy => "myproxy.com:80").
|
515
|
+
connection.class
|
510
516
|
|
511
517
|
assert_equal "myproxy.com",
|
512
518
|
proxy_class.instance_variable_get("@proxy_address")
|
@@ -519,7 +525,8 @@ class TestRequest < Test::Unit::TestCase
|
|
519
525
|
|
520
526
|
|
521
527
|
def test_proxy_no_port
|
522
|
-
proxy_class = Kronk::Request.new("host.com"
|
528
|
+
proxy_class = Kronk::Request.new("host.com", :proxy => "myproxy.com").
|
529
|
+
connection.class
|
523
530
|
|
524
531
|
assert_equal "myproxy.com",
|
525
532
|
proxy_class.instance_variable_get("@proxy_address")
|
@@ -538,7 +545,7 @@ class TestRequest < Test::Unit::TestCase
|
|
538
545
|
:username => "john",
|
539
546
|
:password => "smith" }
|
540
547
|
|
541
|
-
proxy_class = req.
|
548
|
+
proxy_class = req.connection.class
|
542
549
|
|
543
550
|
assert_equal "myproxy.com",
|
544
551
|
proxy_class.instance_variable_get("@proxy_address")
|
@@ -582,4 +589,114 @@ class TestRequest < Test::Unit::TestCase
|
|
582
589
|
assert_equal "some/path", req.path
|
583
590
|
assert_equal "vanilla kronk", req['User-Agent']
|
584
591
|
end
|
592
|
+
|
593
|
+
|
594
|
+
def test_multipart_hash
|
595
|
+
file1 = File.open("test/mocks/200_gzip.txt", "rb")
|
596
|
+
file2 = File.open("test/mocks/200_response.json", "rb")
|
597
|
+
File.stubs(:open).with("test/mocks/200_gzip.txt", "rb").returns file1
|
598
|
+
File.stubs(:open).with("test/mocks/200_response.json", "rb").returns file2
|
599
|
+
|
600
|
+
req = Kronk::Request.new "host.com",
|
601
|
+
:form => {:foo => ["bar"]},
|
602
|
+
:form_upload => {:foo => ["test/mocks/200_gzip.txt"],
|
603
|
+
:bar => "test/mocks/200_response.json"}
|
604
|
+
|
605
|
+
assert_equal Kronk::Multipart, req.body.class
|
606
|
+
assert_equal 3, req.body.parts.length
|
607
|
+
|
608
|
+
expected = [{"content-disposition"=>"form-data; name=\"foo[]\""}, "bar"]
|
609
|
+
assert req.body.parts.include?(expected),
|
610
|
+
"Request body should include foo[]=bar"
|
611
|
+
|
612
|
+
expected = [{
|
613
|
+
'content-disposition' =>
|
614
|
+
"form-data; name=\"foo[]\"; filename=\"#{File.basename file1.path}\"",
|
615
|
+
'Content-Type' => "text/plain",
|
616
|
+
'Content-Transfer-Encoding' => 'binary'
|
617
|
+
}, file1]
|
618
|
+
assert req.body.parts.include?(expected),
|
619
|
+
"Request body should include foo[]=#{file1.inspect}"
|
620
|
+
|
621
|
+
expected = [{
|
622
|
+
'content-disposition' =>
|
623
|
+
"form-data; name=\"bar\"; filename=\"#{File.basename file2.path}\"",
|
624
|
+
'Content-Type' => "application/json",
|
625
|
+
'Content-Transfer-Encoding' => 'binary'
|
626
|
+
}, file2]
|
627
|
+
assert req.body.parts.include?(expected),
|
628
|
+
"Request body should include bar=#{file2.inspect}"
|
629
|
+
|
630
|
+
ensure
|
631
|
+
file1.close
|
632
|
+
file2.close
|
633
|
+
end
|
634
|
+
|
635
|
+
|
636
|
+
def test_multipart_string
|
637
|
+
file1 = File.open("test/mocks/200_gzip.txt", "rb")
|
638
|
+
file2 = File.open("test/mocks/200_response.json", "rb")
|
639
|
+
File.stubs(:open).with("test/mocks/200_gzip.txt", "rb").returns file1
|
640
|
+
File.stubs(:open).with("test/mocks/200_response.json", "rb").returns file2
|
641
|
+
|
642
|
+
req = Kronk::Request.new "host.com",
|
643
|
+
:form => "foo[]=bar",
|
644
|
+
:form_upload =>
|
645
|
+
"foo[]=test/mocks/200_gzip.txt&bar=test/mocks/200_response.json"
|
646
|
+
|
647
|
+
assert_equal Kronk::Multipart, req.body.class
|
648
|
+
assert_equal 3, req.body.parts.length
|
649
|
+
|
650
|
+
expected = [{"content-disposition"=>"form-data; name=\"foo[]\""}, "bar"]
|
651
|
+
assert req.body.parts.include?(expected),
|
652
|
+
"Request body should include foo[]=bar"
|
653
|
+
|
654
|
+
expected = [{
|
655
|
+
'content-disposition' =>
|
656
|
+
"form-data; name=\"foo[]\"; filename=\"#{File.basename file1.path}\"",
|
657
|
+
'Content-Type' => "text/plain",
|
658
|
+
'Content-Transfer-Encoding' => 'binary'
|
659
|
+
}, file1]
|
660
|
+
assert req.body.parts.include?(expected),
|
661
|
+
"Request body should include foo[]=#{file1.inspect}"
|
662
|
+
|
663
|
+
expected = [{
|
664
|
+
'content-disposition' =>
|
665
|
+
"form-data; name=\"bar\"; filename=\"#{File.basename file2.path}\"",
|
666
|
+
'Content-Type' => "application/json",
|
667
|
+
'Content-Transfer-Encoding' => 'binary'
|
668
|
+
}, file2]
|
669
|
+
assert req.body.parts.include?(expected),
|
670
|
+
"Request body should include bar=#{file2.inspect}"
|
671
|
+
|
672
|
+
ensure
|
673
|
+
file1.close
|
674
|
+
file2.close
|
675
|
+
end
|
676
|
+
|
677
|
+
|
678
|
+
def test_http_request_multipart
|
679
|
+
file1 = File.open("test/mocks/200_gzip.txt", "rb")
|
680
|
+
file2 = File.open("test/mocks/200_response.json", "rb")
|
681
|
+
File.stubs(:open).with("test/mocks/200_gzip.txt", "rb").returns file1
|
682
|
+
File.stubs(:open).with("test/mocks/200_response.json", "rb").returns file2
|
683
|
+
|
684
|
+
req = Kronk::Request.new "host.com",
|
685
|
+
:form => "foo[]=bar",
|
686
|
+
:form_upload =>
|
687
|
+
"foo[]=test/mocks/200_gzip.txt&bar=test/mocks/200_response.json"
|
688
|
+
|
689
|
+
hreq = req.http_request
|
690
|
+
assert_equal Kronk::MultipartIO, hreq.body_stream.class
|
691
|
+
assert_equal req.body.to_io.size.to_s, hreq['Content-Length']
|
692
|
+
assert_equal 5, hreq.body_stream.parts.length
|
693
|
+
assert hreq.body_stream.parts.include?(file1),
|
694
|
+
"HTTPRequest body stream should include #{file1.inspect}"
|
695
|
+
assert hreq.body_stream.parts.include?(file2),
|
696
|
+
"HTTPRequest body stream should include #{file2.inspect}"
|
697
|
+
|
698
|
+
ensure
|
699
|
+
file1.close
|
700
|
+
file2.close
|
701
|
+
end
|
585
702
|
end
|
data/test/test_response.rb
CHANGED
@@ -11,6 +11,38 @@ class TestResponse < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
|
14
|
+
def test_ext
|
15
|
+
assert_equal "html", @html_resp.ext
|
16
|
+
assert_equal "json", @json_resp.ext
|
17
|
+
assert_equal "plist", @plist_resp.ext
|
18
|
+
assert_equal "xml", @xml_resp.ext
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def test_ext_file
|
23
|
+
yml = Kronk::Response.
|
24
|
+
read_file("test/mocks/cookies.yml", :allow_headless => true)
|
25
|
+
|
26
|
+
assert_equal "text/x-yaml; charset=ASCII-8BIT", yml.headers['content-type']
|
27
|
+
assert_equal "yaml", yml.ext
|
28
|
+
|
29
|
+
yml.headers.delete('content-type')
|
30
|
+
assert_equal "yml", yml.ext
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_ext_default
|
35
|
+
bin = Kronk::Response.
|
36
|
+
read_file("bin/kronk", :allow_headless => true)
|
37
|
+
|
38
|
+
assert_equal "text/plain; charset=ASCII-8BIT", bin.headers['content-type']
|
39
|
+
assert_equal "txt", bin.ext
|
40
|
+
|
41
|
+
bin.headers.delete('content-type')
|
42
|
+
assert_equal "txt", bin.ext
|
43
|
+
end
|
44
|
+
|
45
|
+
|
14
46
|
def test_init_encoding
|
15
47
|
assert_equal "ISO-8859-1", @html_resp.encoding.to_s
|
16
48
|
assert_equal "ISO-8859-1", @html_resp.body.encoding.to_s if
|
@@ -259,8 +291,8 @@ class TestResponse < Test::Unit::TestCase
|
|
259
291
|
resp = Kronk::Response.new io
|
260
292
|
|
261
293
|
assert_equal "just this one line!", resp.body
|
262
|
-
enc = "".encoding rescue "
|
263
|
-
assert_equal "text/
|
294
|
+
enc = "".encoding rescue "ASCII-8BIT"
|
295
|
+
assert_equal "text/plain; charset=#{enc}", resp['Content-Type']
|
264
296
|
end
|
265
297
|
|
266
298
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kronk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.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: 2012-
|
12
|
+
date: 2012-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mime-types
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.18.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.18.0
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: rdoc
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +165,7 @@ description: ! 'Kronk is a command line swiss-army-knife for HTTP services.
|
|
149
165
|
your HTTP applications.
|
150
166
|
|
151
167
|
|
152
|
-
Kronk was made possible by the sponsoring of
|
168
|
+
Kronk was made possible by the sponsoring of YP.com.'
|
153
169
|
email:
|
154
170
|
- yaksnrainbows@gmail.com
|
155
171
|
executables:
|
@@ -168,6 +184,7 @@ files:
|
|
168
184
|
- Rakefile
|
169
185
|
- bin/kronk
|
170
186
|
- lib/kronk.rb
|
187
|
+
- lib/kronk/buffered_io.rb
|
171
188
|
- lib/kronk/cmd.rb
|
172
189
|
- lib/kronk/constants.rb
|
173
190
|
- lib/kronk/data_string.rb
|
@@ -176,9 +193,11 @@ files:
|
|
176
193
|
- lib/kronk/diff/color_format.rb
|
177
194
|
- lib/kronk/diff/output.rb
|
178
195
|
- lib/kronk/http.rb
|
179
|
-
- lib/kronk/
|
196
|
+
- lib/kronk/multipart.rb
|
197
|
+
- lib/kronk/multipart_io.rb
|
180
198
|
- lib/kronk/player.rb
|
181
199
|
- lib/kronk/player/benchmark.rb
|
200
|
+
- lib/kronk/player/download.rb
|
182
201
|
- lib/kronk/player/input_reader.rb
|
183
202
|
- lib/kronk/player/request_parser.rb
|
184
203
|
- lib/kronk/player/suite.rb
|
@@ -212,6 +231,8 @@ files:
|
|
212
231
|
- test/test_helper_methods.rb
|
213
232
|
- test/test_input_reader.rb
|
214
233
|
- test/test_kronk.rb
|
234
|
+
- test/test_multipart.rb
|
235
|
+
- test/test_multipart_io.rb
|
215
236
|
- test/test_player.rb
|
216
237
|
- test/test_request.rb
|
217
238
|
- test/test_request_parser.rb
|
@@ -254,6 +275,8 @@ test_files:
|
|
254
275
|
- test/test_helper_methods.rb
|
255
276
|
- test/test_input_reader.rb
|
256
277
|
- test/test_kronk.rb
|
278
|
+
- test/test_multipart.rb
|
279
|
+
- test/test_multipart_io.rb
|
257
280
|
- test/test_player.rb
|
258
281
|
- test/test_request.rb
|
259
282
|
- test/test_request_parser.rb
|