kronk 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +15 -1
- data/TODO.rdoc +6 -0
- data/bin/kronk +1 -1
- data/lib/kronk.rb +8 -9
- data/lib/kronk/cmd.rb +43 -15
- data/lib/kronk/constants.rb +1 -0
- data/lib/kronk/request.rb +62 -12
- data/lib/kronk/response.rb +2 -0
- data/script/kronk_completion +10 -2
- data/test/test_cmd.rb +9 -8
- data/test/test_helper.rb +3 -2
- data/test/test_helper_methods.rb +6 -3
- data/test/test_kronk.rb +4 -1
- data/test/test_player.rb +3 -3
- data/test/test_request.rb +65 -0
- metadata +14 -14
data/History.rdoc
CHANGED
@@ -1,4 +1,18 @@
|
|
1
|
-
=== 1.8.
|
1
|
+
=== 1.8.1 / 2012-02-07
|
2
|
+
|
3
|
+
* Enhancements:
|
4
|
+
|
5
|
+
* Support max number of history items.
|
6
|
+
|
7
|
+
* Support --form option to set form-encoded content type.
|
8
|
+
|
9
|
+
* Support file uploads.
|
10
|
+
|
11
|
+
* Bugfixes:
|
12
|
+
|
13
|
+
* Don't override Cookies set via the -H option.
|
14
|
+
|
15
|
+
=== 1.8.0 / 2012-01-05
|
2
16
|
|
3
17
|
* Major Enhancements:
|
4
18
|
|
data/TODO.rdoc
CHANGED
data/bin/kronk
CHANGED
data/lib/kronk.rb
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
-
require 'rubygems'
|
1
|
+
require 'rubygems' if RUBY_VERSION =~ /1.8/
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'cookiejar'
|
5
5
|
|
6
6
|
require 'thread'
|
7
7
|
require 'stringio'
|
8
|
-
require 'base64'
|
9
8
|
|
10
|
-
require 'net/
|
11
|
-
require 'zlib'
|
12
|
-
require 'optparse'
|
9
|
+
require 'net/http'
|
13
10
|
require 'yaml'
|
14
11
|
|
15
12
|
class Kronk
|
16
13
|
|
17
14
|
# This gem's version.
|
18
|
-
VERSION = '1.8.
|
15
|
+
VERSION = '1.8.1'
|
19
16
|
|
20
17
|
require 'kronk/constants'
|
21
18
|
require 'kronk/queue_runner'
|
@@ -26,7 +23,6 @@ class Kronk
|
|
26
23
|
require 'kronk/player/tsv'
|
27
24
|
require 'kronk/player/request_parser'
|
28
25
|
require 'kronk/player/input_reader'
|
29
|
-
require 'kronk/cmd'
|
30
26
|
require 'kronk/path'
|
31
27
|
require 'kronk/path/match'
|
32
28
|
require 'kronk/path/matcher'
|
@@ -225,7 +221,7 @@ class Kronk
|
|
225
221
|
# Writes the URL history to the history file.
|
226
222
|
|
227
223
|
def self.save_history
|
228
|
-
history_str = self.history.uniq.join($/)
|
224
|
+
history_str = self.history.uniq[0..self.config[:max_history]].join($/)
|
229
225
|
|
230
226
|
File.open self.config[:history_file], "w" do |file|
|
231
227
|
file.write history_str
|
@@ -342,7 +338,10 @@ class Kronk
|
|
342
338
|
req = Request.new uri, options
|
343
339
|
Cmd.verbose "Retrieving URL: #{req.uri}\n"
|
344
340
|
resp = req.retrieve options
|
345
|
-
|
341
|
+
|
342
|
+
hist_uri = req.uri.to_s[0..-req.uri.request_uri.length]
|
343
|
+
hist_uri = hist_uri[(req.uri.scheme.length + 3)..-1]
|
344
|
+
Kronk.history << hist_uri
|
346
345
|
end
|
347
346
|
|
348
347
|
resp.parser = options[:parser] if options[:parser]
|
data/lib/kronk/cmd.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'kronk'
|
2
|
+
require 'optparse'
|
3
|
+
|
1
4
|
class Kronk
|
2
5
|
|
3
6
|
##
|
@@ -185,6 +188,12 @@ Parse and run diffs against data from live and cached http responses.
|
|
185
188
|
end
|
186
189
|
|
187
190
|
|
191
|
+
opt.on('-h', '--help', 'Print this help screen') do
|
192
|
+
puts opt
|
193
|
+
exit
|
194
|
+
end
|
195
|
+
|
196
|
+
|
188
197
|
opt.on('-i', '--include [HEADER1,HEADER2]', Array,
|
189
198
|
'Include all or given headers in response') do |value|
|
190
199
|
options[:show_headers] ||= []
|
@@ -283,6 +292,12 @@ Parse and run diffs against data from live and cached http responses.
|
|
283
292
|
end
|
284
293
|
|
285
294
|
|
295
|
+
opt.on('-v', '--version', 'Output Kronk version and exit') do
|
296
|
+
puts Kronk::VERSION
|
297
|
+
exit
|
298
|
+
end
|
299
|
+
|
300
|
+
|
286
301
|
opt.separator <<-STR
|
287
302
|
|
288
303
|
Player Options:
|
@@ -363,6 +378,12 @@ Parse and run diffs against data from live and cached http responses.
|
|
363
378
|
end
|
364
379
|
|
365
380
|
|
381
|
+
opt.on('-F', '--form STR', String,
|
382
|
+
'Set request body with form headers; overrides -d') do |value|
|
383
|
+
options[:form] = value
|
384
|
+
end
|
385
|
+
|
386
|
+
|
366
387
|
opt.on('-H', '--header STR', String,
|
367
388
|
'Header to pass to the server request') do |value|
|
368
389
|
options[:headers] ||= {}
|
@@ -372,12 +393,6 @@ Parse and run diffs against data from live and cached http responses.
|
|
372
393
|
end
|
373
394
|
|
374
395
|
|
375
|
-
opt.on('-A', '--user-agent STR', String,
|
376
|
-
'User-Agent to send to server or a valid alias') do |value|
|
377
|
-
options[:user_agent] = value
|
378
|
-
end
|
379
|
-
|
380
|
-
|
381
396
|
opt.on('-L', '--location [NUM]', Integer,
|
382
397
|
'Follow the location header always or num times') do |value|
|
383
398
|
options[:follow_redirects] = value || true
|
@@ -396,12 +411,27 @@ Parse and run diffs against data from live and cached http responses.
|
|
396
411
|
end
|
397
412
|
|
398
413
|
|
414
|
+
opt.on('-U', '--proxy-user STR', String,
|
415
|
+
'Set proxy user and/or password: usr[:pass]') do |value|
|
416
|
+
options[:proxy][:username], options[:proxy][:password] =
|
417
|
+
value.split ":", 2
|
418
|
+
|
419
|
+
options[:proxy][:password] ||= query_password "Proxy password:"
|
420
|
+
end
|
421
|
+
|
422
|
+
|
399
423
|
opt.on('-?', '--query STR', String,
|
400
424
|
'Append query to URLs') do |value|
|
401
425
|
options[:query] = value
|
402
426
|
end
|
403
427
|
|
404
428
|
|
429
|
+
opt.on('-X', '--request STR', String,
|
430
|
+
'The HTTP request method to use') do |value|
|
431
|
+
options[:http_method] = value
|
432
|
+
end
|
433
|
+
|
434
|
+
|
405
435
|
opt.on('--suff STR', String,
|
406
436
|
'Add common path items to the end of each URL') do |value|
|
407
437
|
options[:uri_suffix] = value
|
@@ -414,12 +444,10 @@ Parse and run diffs against data from live and cached http responses.
|
|
414
444
|
end
|
415
445
|
|
416
446
|
|
417
|
-
opt.on('-
|
418
|
-
'
|
419
|
-
options[:
|
420
|
-
|
421
|
-
|
422
|
-
options[:proxy][:password] ||= query_password "Proxy password:"
|
447
|
+
opt.on('-T', '--upload-file FILE', String,
|
448
|
+
'Transfer file in HTTP body') do |file|
|
449
|
+
options[:data] = File.open(file, 'rb')
|
450
|
+
options[:http_method] ||= 'POST'
|
423
451
|
end
|
424
452
|
|
425
453
|
|
@@ -432,9 +460,9 @@ Parse and run diffs against data from live and cached http responses.
|
|
432
460
|
end
|
433
461
|
|
434
462
|
|
435
|
-
opt.on('-
|
436
|
-
'
|
437
|
-
options[:
|
463
|
+
opt.on('-A', '--user-agent STR', String,
|
464
|
+
'User-Agent to send to server or a valid alias') do |value|
|
465
|
+
options[:user_agent] = value
|
438
466
|
end
|
439
467
|
|
440
468
|
|
data/lib/kronk/constants.rb
CHANGED
data/lib/kronk/request.rb
CHANGED
@@ -199,14 +199,15 @@ class Kronk
|
|
199
199
|
end
|
200
200
|
|
201
201
|
|
202
|
-
attr_accessor :
|
202
|
+
attr_accessor :headers, :proxy, :response, :timeout
|
203
203
|
|
204
|
-
attr_reader :http_method, :uri, :use_cookies
|
204
|
+
attr_reader :body, :http_method, :uri, :use_cookies
|
205
205
|
|
206
206
|
##
|
207
207
|
# Build an http request to the given uri and return a Response instance.
|
208
208
|
# Supports the following options:
|
209
|
-
# :data:: Hash/String - the data to pass to the http request
|
209
|
+
# :data:: Hash/String - the data to pass to the http request body
|
210
|
+
# :form:: Hash/String - similar to :data but sets content-type header
|
210
211
|
# :query:: Hash/String - the data to append to the http request path
|
211
212
|
# :user_agent:: String - user agent string or alias; defaults to 'kronk'
|
212
213
|
# :auth:: Hash - must contain :username and :password; defaults to nil
|
@@ -221,12 +222,10 @@ class Kronk
|
|
221
222
|
def initialize uri, opts={}
|
222
223
|
@auth = opts[:auth]
|
223
224
|
|
224
|
-
@body = nil
|
225
|
-
@body = self.class.build_query opts[:data] if opts[:data]
|
226
|
-
|
227
225
|
@connection = nil
|
228
|
-
@response
|
229
|
-
@
|
226
|
+
@response = nil
|
227
|
+
@body = nil
|
228
|
+
@_req = nil
|
230
229
|
|
231
230
|
@headers = opts[:headers] || {}
|
232
231
|
|
@@ -243,6 +242,9 @@ class Kronk
|
|
243
242
|
@proxy = opts[:proxy] || {}
|
244
243
|
@proxy = {:host => @proxy} unless Hash === @proxy
|
245
244
|
|
245
|
+
self.body = opts[:data] if opts[:data]
|
246
|
+
self.form_data = opts[:form] if opts[:form]
|
247
|
+
|
246
248
|
self.user_agent ||= opts[:user_agent]
|
247
249
|
|
248
250
|
self.http_method = opts[:http_method] || (@body ? "POST" : "GET")
|
@@ -259,6 +261,7 @@ class Kronk
|
|
259
261
|
@auth ||= Hash.new
|
260
262
|
|
261
263
|
if !@auth[:username] && @headers['Authorization']
|
264
|
+
require 'base64'
|
262
265
|
str = Base64.decode64 @headers['Authorization'].split[1]
|
263
266
|
username, password = str.split(":", 2)
|
264
267
|
@auth = {:username => username, :password => password}.merge @auth
|
@@ -268,6 +271,30 @@ class Kronk
|
|
268
271
|
end
|
269
272
|
|
270
273
|
|
274
|
+
##
|
275
|
+
# Assign request body. Supports String, Hash, and IO.
|
276
|
+
|
277
|
+
def body= data
|
278
|
+
case data
|
279
|
+
when Hash
|
280
|
+
self.form_data = data
|
281
|
+
|
282
|
+
when String
|
283
|
+
dont_chunk!
|
284
|
+
@body = data
|
285
|
+
|
286
|
+
else
|
287
|
+
if data.respond_to?(:read)
|
288
|
+
@headers['Transfer-Encoding'] = 'chunked'
|
289
|
+
@body = data
|
290
|
+
else
|
291
|
+
dont_chunk!
|
292
|
+
@body = data.to_s
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
|
271
298
|
##
|
272
299
|
# Reference to the HTTP connection instance.
|
273
300
|
|
@@ -277,7 +304,11 @@ class Kronk
|
|
277
304
|
|
278
305
|
@connection = http_class.new @uri.host, @uri.port
|
279
306
|
@connection.open_timeout = @connection.read_timeout = @timeout if @timeout
|
280
|
-
|
307
|
+
|
308
|
+
if @uri.scheme =~ /^https$/
|
309
|
+
require 'net/https'
|
310
|
+
@connection.use_ssl = true
|
311
|
+
end
|
281
312
|
|
282
313
|
@connection
|
283
314
|
end
|
@@ -291,6 +322,16 @@ class Kronk
|
|
291
322
|
end
|
292
323
|
|
293
324
|
|
325
|
+
##
|
326
|
+
# Assigns body of the request with form headers.
|
327
|
+
|
328
|
+
def form_data= data
|
329
|
+
dont_chunk!
|
330
|
+
@headers['Content-Type'] = "application/x-www-form-urlencoded"
|
331
|
+
@body = self.class.build_query data
|
332
|
+
end
|
333
|
+
|
334
|
+
|
294
335
|
##
|
295
336
|
# Assigns the http method.
|
296
337
|
|
@@ -307,7 +348,7 @@ class Kronk
|
|
307
348
|
cookie = Kronk.cookie_jar.get_cookie_header @uri.to_s
|
308
349
|
@headers['Cookie'] = cookie unless cookie.empty?
|
309
350
|
|
310
|
-
|
351
|
+
elsif !bool
|
311
352
|
@headers.delete 'Cookie'
|
312
353
|
end
|
313
354
|
|
@@ -365,7 +406,7 @@ class Kronk
|
|
365
406
|
|
366
407
|
@response = connection.start do |http|
|
367
408
|
start_time = Time.now
|
368
|
-
res = http.request http_request,
|
409
|
+
res = http.request http_request, nil, opts, &block
|
369
410
|
res.body # make sure to read the full body from io
|
370
411
|
res.time = Time.now - start_time
|
371
412
|
res.request = self
|
@@ -442,7 +483,7 @@ class Kronk
|
|
442
483
|
|
443
484
|
|
444
485
|
##
|
445
|
-
# Returns the
|
486
|
+
# Returns the Net::HTTPRequest subclass instance.
|
446
487
|
|
447
488
|
def http_request
|
448
489
|
req = VanillaRequest.new @http_method, @uri.request_uri, @headers
|
@@ -450,6 +491,8 @@ class Kronk
|
|
450
491
|
req.basic_auth @auth[:username], @auth[:password] if
|
451
492
|
@auth && @auth[:username]
|
452
493
|
|
494
|
+
@body.respond_to?(:read) ? req.body_stream = @body : req.body = @body
|
495
|
+
|
453
496
|
req
|
454
497
|
end
|
455
498
|
|
@@ -473,6 +516,13 @@ class Kronk
|
|
473
516
|
Kronk::HTTP::Proxy host, port, user, pass
|
474
517
|
end
|
475
518
|
|
519
|
+
private
|
520
|
+
|
521
|
+
|
522
|
+
def dont_chunk!
|
523
|
+
@headers.delete('Transfer-Encoding') if
|
524
|
+
@headers['Transfer-Encoding'].to_s.downcase == 'chunked'
|
525
|
+
end
|
476
526
|
|
477
527
|
|
478
528
|
##
|
data/lib/kronk/response.rb
CHANGED
data/script/kronk_completion
CHANGED
@@ -4,15 +4,23 @@ export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
|
|
4
4
|
|
5
5
|
_kronk()
|
6
6
|
{
|
7
|
-
local cur kronk_keys
|
7
|
+
local cur kronk_keys kronk_words
|
8
8
|
|
9
9
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
10
10
|
|
11
11
|
kronk_keys="$HOME/.kronk/history"
|
12
12
|
test -f "$kronk_keys" || kronk_keys="$HOME/.kronk_history"
|
13
13
|
|
14
|
+
kronk_words="$(cat $kronk_keys | sed 's/^http*:\/\///')"
|
15
|
+
|
16
|
+
if [[ ${cur:0:1} == "h" ]]; then
|
17
|
+
kronk_words="$(echo "$kronk_words" | sed 's/^/http:\/\//')
|
18
|
+
$(echo "$kronk_words" | sed 's/^/https:\/\//')
|
19
|
+
$(echo "$kronk_words")"
|
20
|
+
fi
|
21
|
+
|
14
22
|
if [ -f "$kronk_keys" ]; then
|
15
|
-
COMPREPLY=( $(compgen -W "$
|
23
|
+
COMPREPLY=( $(compgen -W "$kronk_words" -- ${cur}) )
|
16
24
|
return 0
|
17
25
|
fi
|
18
26
|
|
data/test/test_cmd.rb
CHANGED
@@ -352,14 +352,15 @@ class TestCmd < Test::Unit::TestCase
|
|
352
352
|
|
353
353
|
def test_parse_args_http_options
|
354
354
|
opts = Kronk::Cmd.parse_args %w{uri -A foo -L --no-cookies -? bar
|
355
|
-
--suff /tail -X PUT -x example.com:2000}
|
356
|
-
|
357
|
-
assert_equal "foo",
|
358
|
-
assert_equal true,
|
359
|
-
assert_equal true,
|
360
|
-
assert_equal "bar",
|
361
|
-
assert_equal "/tail",
|
362
|
-
assert_equal "PUT",
|
355
|
+
--suff /tail -X PUT -x example.com:2000 --form foo=bar}
|
356
|
+
|
357
|
+
assert_equal "foo", opts[:user_agent]
|
358
|
+
assert_equal true, opts[:follow_redirects]
|
359
|
+
assert_equal true, opts[:no_cookies]
|
360
|
+
assert_equal "bar", opts[:query]
|
361
|
+
assert_equal "/tail", opts[:uri_suffix]
|
362
|
+
assert_equal "PUT", opts[:http_method]
|
363
|
+
assert_equal "foo=bar", opts[:form]
|
363
364
|
assert_equal({:host => "example.com", :port => "2000"}, opts[:proxy])
|
364
365
|
|
365
366
|
opts = Kronk::Cmd.parse_args %w{uri -L 3}
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "test/unit"
|
2
2
|
require "mocha"
|
3
|
-
require "kronk"
|
3
|
+
require "kronk/cmd"
|
4
4
|
|
5
5
|
Kronk.config[:context] = nil
|
6
6
|
|
@@ -176,6 +176,7 @@ def expect_request req_method, url, options={}
|
|
176
176
|
headers['User-Agent'] ||= Kronk::DEFAULT_USER_AGENT
|
177
177
|
|
178
178
|
req.expects(:start).yields(http).returns resp
|
179
|
+
req.expects(:body=).with(data)
|
179
180
|
|
180
181
|
Kronk::Request::VanillaRequest.expects(:new).
|
181
182
|
with(req_method.to_s.upcase, uri.request_uri, headers).returns req
|
@@ -183,7 +184,7 @@ def expect_request req_method, url, options={}
|
|
183
184
|
Kronk::HTTP.expects(:new).with(uri.host, uri.port).returns req
|
184
185
|
|
185
186
|
http.expects(:request).
|
186
|
-
with(req,
|
187
|
+
with(req, nil, has_entry(:request => instance_of(Kronk::Request))).
|
187
188
|
returns resp
|
188
189
|
|
189
190
|
yield http, req, resp if block_given?
|
data/test/test_helper_methods.rb
CHANGED
@@ -10,8 +10,10 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
10
10
|
@mock_resp = Kronk::Response.new io
|
11
11
|
@mock_resp2 = Kronk::Response.new \
|
12
12
|
StringIO.new mock_resp("200_response.json")
|
13
|
-
@mock_req = stub("mock_req", :retrieve => @mock_resp,
|
14
|
-
|
13
|
+
@mock_req = stub("mock_req", :retrieve => @mock_resp,
|
14
|
+
:uri => URI.parse("http://host.com"))
|
15
|
+
@mock_req2 = stub("mock_req", :retrieve => @mock_resp2,
|
16
|
+
:uri => URI.parse("http://host.com"))
|
15
17
|
|
16
18
|
@mock_thread = stub("mock_thread", :join => true,
|
17
19
|
:abort_on_exception= => true)
|
@@ -140,7 +142,8 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
140
142
|
|
141
143
|
def test_retrieve_unparsable
|
142
144
|
mock_resp = Kronk::Response.new StringIO.new(mock_200_response)
|
143
|
-
mock_req = stub("mock_req", :retrieve => mock_resp,
|
145
|
+
mock_req = stub("mock_req", :retrieve => mock_resp,
|
146
|
+
:uri => URI.parse("http://host.com"))
|
144
147
|
|
145
148
|
Kronk::Request.expects(:new).
|
146
149
|
with("host.com", :foo => "bar").returns mock_req
|
data/test/test_kronk.rb
CHANGED
@@ -16,9 +16,10 @@ class TestKronk < Test::Unit::TestCase
|
|
16
16
|
:cache_file => Kronk::DEFAULT_CACHE_FILE,
|
17
17
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
18
18
|
:history_file => Kronk::DEFAULT_HISTORY_FILE,
|
19
|
-
:indentation
|
19
|
+
:indentation => 1,
|
20
20
|
:default_host => "http://localhost:3000",
|
21
21
|
:diff_format => 'ascii',
|
22
|
+
:max_history => 100,
|
22
23
|
:show_lines => false,
|
23
24
|
:use_cookies => true,
|
24
25
|
:requires => [],
|
@@ -43,6 +44,7 @@ class TestKronk < Test::Unit::TestCase
|
|
43
44
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
44
45
|
:history_file => Kronk::DEFAULT_HISTORY_FILE,
|
45
46
|
:indentation => 1,
|
47
|
+
:max_history => 100,
|
46
48
|
:show_lines => false,
|
47
49
|
:use_cookies => true,
|
48
50
|
:requires => [],
|
@@ -78,6 +80,7 @@ class TestKronk < Test::Unit::TestCase
|
|
78
80
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
79
81
|
:history_file => Kronk::DEFAULT_HISTORY_FILE,
|
80
82
|
:indentation => 1,
|
83
|
+
:max_history => 100,
|
81
84
|
:requires => [],
|
82
85
|
:show_lines => false,
|
83
86
|
:use_cookies => true,
|
data/test/test_player.rb
CHANGED
@@ -522,11 +522,11 @@ class TestPlayer < Test::Unit::TestCase
|
|
522
522
|
end
|
523
523
|
|
524
524
|
req.each_with_index do |r, i|
|
525
|
-
mock_req = "mock request"
|
526
525
|
mock_res = Kronk::Response.new resp[i]
|
526
|
+
mock_req = stub("mock_req", :retrieve => mock_res,
|
527
|
+
:uri => URI.parse("http://host.com"))
|
528
|
+
|
527
529
|
Kronk::Request.stubs(:new).with(req[i], opts).returns mock_req
|
528
|
-
mock_req.stubs(:retrieve).returns mock_res
|
529
|
-
mock_req.stubs(:uri).returns nil
|
530
530
|
end
|
531
531
|
end
|
532
532
|
end
|
data/test/test_request.rb
CHANGED
@@ -140,6 +140,51 @@ class TestRequest < Test::Unit::TestCase
|
|
140
140
|
end
|
141
141
|
|
142
142
|
|
143
|
+
def test_body_hash
|
144
|
+
req = Kronk::Request.new "foo.com"
|
145
|
+
req.headers['Transfer-Encoding'] = "chunked"
|
146
|
+
req.body = {:foo => :bar}
|
147
|
+
|
148
|
+
assert_equal "foo=bar", req.body
|
149
|
+
assert_equal nil, req.headers['Transfer-Encoding']
|
150
|
+
assert_equal "application/x-www-form-urlencoded",
|
151
|
+
req.headers['Content-Type']
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def test_body_string
|
156
|
+
req = Kronk::Request.new "foo.com", :form => "blah"
|
157
|
+
req.headers['Transfer-Encoding'] = "chunked"
|
158
|
+
req.body = "foo=bar"
|
159
|
+
|
160
|
+
assert_equal "foo=bar", req.body
|
161
|
+
assert_equal nil, req.headers['Transfer-Encoding']
|
162
|
+
assert_equal "application/x-www-form-urlencoded",
|
163
|
+
req.headers['Content-Type']
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
def test_body_io
|
168
|
+
req = Kronk::Request.new "foo.com"
|
169
|
+
req.body = str_io = StringIO.new "foo=bar"
|
170
|
+
|
171
|
+
assert_equal str_io, req.body
|
172
|
+
assert_equal 'chunked', req.headers['Transfer-Encoding']
|
173
|
+
assert_equal nil, req.headers['Content-Type']
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
def test_body_other
|
178
|
+
req = Kronk::Request.new "foo.com"
|
179
|
+
req.headers['Transfer-Encoding'] = "chunked"
|
180
|
+
req.body = 12345
|
181
|
+
|
182
|
+
assert_equal "12345", req.body
|
183
|
+
assert_equal nil, req.headers['Transfer-Encoding']
|
184
|
+
assert_equal nil, req.headers['Content-Type']
|
185
|
+
end
|
186
|
+
|
187
|
+
|
143
188
|
def test_retrieve_get
|
144
189
|
expect_request "GET", "http://example.com/request/path?foo=bar"
|
145
190
|
resp =
|
@@ -329,6 +374,26 @@ class TestRequest < Test::Unit::TestCase
|
|
329
374
|
end
|
330
375
|
|
331
376
|
|
377
|
+
def test_form_option
|
378
|
+
req = Kronk::Request.new("http://example.com", :data => "foo",
|
379
|
+
:form => "bar")
|
380
|
+
|
381
|
+
assert_equal "bar", req.body
|
382
|
+
assert_equal "application/x-www-form-urlencoded",
|
383
|
+
req.headers['Content-Type']
|
384
|
+
end
|
385
|
+
|
386
|
+
|
387
|
+
def test_form_data
|
388
|
+
req = Kronk::Request.new("http://example.com", :data => "foo",
|
389
|
+
:form => "bar")
|
390
|
+
|
391
|
+
assert_equal "bar", req.body
|
392
|
+
assert_equal "application/x-www-form-urlencoded",
|
393
|
+
req.headers['Content-Type']
|
394
|
+
end
|
395
|
+
|
396
|
+
|
332
397
|
def test_retrieve_user_agent_default
|
333
398
|
expect_request "GET", "http://example.com",
|
334
399
|
:headers => {
|
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.8.
|
4
|
+
version: 1.8.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70313458309720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.5'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70313458309720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cookiejar
|
27
|
-
requirement: &
|
27
|
+
requirement: &70313459885080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70313459885080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: plist
|
38
|
-
requirement: &
|
38
|
+
requirement: &70313459883680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.1.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70313459883680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: nokogiri
|
49
|
-
requirement: &
|
49
|
+
requirement: &70313459881520 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.4'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70313459881520
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &70313459880540 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.9.12
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70313459880540
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hoe
|
71
|
-
requirement: &
|
71
|
+
requirement: &70313459878740 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '2.12'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70313459878740
|
80
80
|
description: ! 'Kronk runs diffs against data from live and cached http responses.
|
81
81
|
|
82
82
|
Kronk was made possible by the sponsoring of AT&T Interactive.'
|