kronk 1.8.6 → 1.8.7
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 +14 -0
- data/lib/kronk.rb +54 -21
- data/lib/kronk/request.rb +1 -1
- data/lib/kronk/response.rb +10 -2
- metadata +2 -2
data/History.rdoc
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
=== 1.8.7 / 2012-04-30
|
2
|
+
|
3
|
+
* Enhancements:
|
4
|
+
|
5
|
+
* Add support for Kronk request middleware for plugins.
|
6
|
+
|
7
|
+
* Bugfixes:
|
8
|
+
|
9
|
+
* Follow browser conventions and redirect 302s like 303s.
|
10
|
+
|
11
|
+
* Fix passing previous request options to redirects.
|
12
|
+
|
13
|
+
* Fix response stringify options with redirects.
|
14
|
+
|
1
15
|
=== 1.8.6 / 2012-04-23
|
2
16
|
|
3
17
|
* Enhancements:
|
data/lib/kronk.rb
CHANGED
@@ -13,7 +13,7 @@ require 'yaml'
|
|
13
13
|
class Kronk
|
14
14
|
|
15
15
|
# This gem's version.
|
16
|
-
VERSION = '1.8.
|
16
|
+
VERSION = '1.8.7'
|
17
17
|
|
18
18
|
require 'kronk/constants'
|
19
19
|
require 'kronk/queue_runner'
|
@@ -226,6 +226,22 @@ class Kronk
|
|
226
226
|
end
|
227
227
|
|
228
228
|
|
229
|
+
##
|
230
|
+
# Returns an array of middleware to use around requests.
|
231
|
+
|
232
|
+
def self.middleware
|
233
|
+
@middleware ||= []
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
##
|
238
|
+
# Assign middleware to use.
|
239
|
+
|
240
|
+
def self.use mware
|
241
|
+
self.middleware.unshift mware
|
242
|
+
end
|
243
|
+
|
244
|
+
|
229
245
|
##
|
230
246
|
# See Kronk#compare. Short for:
|
231
247
|
# Kronk.new(opts).compare(uri1, uri2)
|
@@ -278,6 +294,9 @@ class Kronk
|
|
278
294
|
@diff = nil
|
279
295
|
@responses = []
|
280
296
|
@response = nil
|
297
|
+
|
298
|
+
meth = method(:request_explicit)
|
299
|
+
@app = Kronk.middleware.inject(meth){|app, mware| mware.new(app) }
|
281
300
|
end
|
282
301
|
|
283
302
|
|
@@ -319,35 +338,21 @@ class Kronk
|
|
319
338
|
|
320
339
|
def request uri
|
321
340
|
options = Kronk.config[:no_uri_options] ? @options : options_for_uri(uri)
|
341
|
+
options.merge!(:uri => uri)
|
322
342
|
|
323
|
-
|
324
|
-
Cmd.verbose "Reading IO #{uri}"
|
325
|
-
resp = Response.new uri, options
|
326
|
-
|
327
|
-
elsif File.file? uri.to_s
|
328
|
-
Cmd.verbose "Reading file: #{uri}\n"
|
329
|
-
resp = Response.read_file uri, options
|
330
|
-
|
331
|
-
else
|
332
|
-
req = Request.new uri, options
|
333
|
-
Cmd.verbose "Retrieving URL: #{req.uri}\n"
|
334
|
-
resp = req.retrieve options
|
335
|
-
|
336
|
-
hist_uri = req.uri.to_s[0..-req.uri.request_uri.length]
|
337
|
-
hist_uri = hist_uri[(req.uri.scheme.length + 3)..-1]
|
338
|
-
Kronk.history << hist_uri
|
339
|
-
end
|
340
|
-
|
341
|
-
resp.parser = options[:parser] if options[:parser]
|
342
|
-
resp.stringify_opts = options
|
343
|
+
resp = @app.call options
|
343
344
|
|
344
345
|
rdir = options[:follow_redirects]
|
345
346
|
while resp.redirect? && (rdir == true || rdir.to_s.to_i > 0)
|
347
|
+
uri = resp.location
|
346
348
|
Cmd.verbose "Following redirect to #{resp.location}"
|
347
349
|
resp = resp.follow_redirect options_for_uri(resp.location)
|
348
350
|
rdir = rdir - 1 if Fixnum === rdir
|
349
351
|
end
|
350
352
|
|
353
|
+
resp.parser = options[:parser] if options[:parser]
|
354
|
+
resp.stringify_opts = options
|
355
|
+
|
351
356
|
@responses = [resp]
|
352
357
|
@response = resp
|
353
358
|
@diff = nil
|
@@ -364,6 +369,34 @@ class Kronk
|
|
364
369
|
alias retrieve request
|
365
370
|
|
366
371
|
|
372
|
+
##
|
373
|
+
# Request without autofilling options.
|
374
|
+
|
375
|
+
def request_explicit opts
|
376
|
+
uri = opts.delete(:uri)
|
377
|
+
|
378
|
+
if IO === uri || StringIO === uri || BufferedIO === uri
|
379
|
+
Cmd.verbose "Reading IO #{uri}"
|
380
|
+
Response.new uri, options
|
381
|
+
|
382
|
+
elsif File.file? uri.to_s
|
383
|
+
Cmd.verbose "Reading file: #{uri}\n"
|
384
|
+
Response.read_file uri, options
|
385
|
+
|
386
|
+
else
|
387
|
+
req = Request.new uri, options
|
388
|
+
Cmd.verbose "Retrieving URL: #{req.uri}\n"
|
389
|
+
resp = req.retrieve options
|
390
|
+
|
391
|
+
hist_uri = req.uri.to_s[0..-req.uri.request_uri.length]
|
392
|
+
hist_uri = hist_uri[(req.uri.scheme.length + 3)..-1]
|
393
|
+
Kronk.history << hist_uri
|
394
|
+
|
395
|
+
resp
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
|
367
400
|
##
|
368
401
|
# Returns merged config-defined options for a given uri.
|
369
402
|
# Values in cmd_opts take precedence.
|
data/lib/kronk/request.rb
CHANGED
data/lib/kronk/response.rb
CHANGED
@@ -501,13 +501,21 @@ class Kronk
|
|
501
501
|
return if !redirect?
|
502
502
|
new_opts = @request ? @request.to_hash : {}
|
503
503
|
|
504
|
-
|
505
|
-
|
504
|
+
if @code == "303" || @code == "302"
|
505
|
+
new_opts[:http_method] = "GET"
|
506
|
+
new_opts.delete(:form)
|
507
|
+
new_opts.delete(:data)
|
508
|
+
end
|
506
509
|
|
510
|
+
new_opts.delete(:headers)
|
511
|
+
new_opts.delete(:host)
|
507
512
|
new_opts.delete(:path)
|
513
|
+
|
508
514
|
new_opts.delete(:auth) if !opts[:trust_location] &&
|
509
515
|
(!@request || self.location.host != self.uri.host)
|
510
516
|
|
517
|
+
new_opts.merge!(opts)
|
518
|
+
|
511
519
|
Request.new(self.location, new_opts).retrieve(new_opts, &block)
|
512
520
|
end
|
513
521
|
|
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.7
|
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-04-
|
12
|
+
date: 2012-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|