nethttputils 0.3.2.6 → 0.3.2.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.
- checksums.yaml +4 -4
- data/lib/nethttputils.rb +31 -6
- data/nethttputils.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ef478ad663a8500e057309f2fcb9bb3587a2525
|
4
|
+
data.tar.gz: 82ccf697e5a37a3d7a46a216ece1e1d5a0498e8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eddfd6fee3905ebd37c9863f0ce420befdb5ee19b4ec2414a05b5be808606032abd3e4bff0ce701a4b8fcb5584e9bbf2b3af8e9e660198bcf668bf296dab860
|
7
|
+
data.tar.gz: 1efd44dfd6afb4b1bbe3657f51a5dde2535715c4576b5126e48e827836848d2b263f7264094a5307da61031d860c80c04060779b2d16351690659d88cc83f84a
|
data/lib/nethttputils.rb
CHANGED
@@ -201,10 +201,17 @@ module NetHTTPUtils
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
+
# TODO: use WEBrick::Cookie
|
205
|
+
old_cookies = cookies.dup
|
204
206
|
response.to_hash.fetch("set-cookie", []).each do |c|
|
205
|
-
|
206
|
-
logger.debug "set-cookie: #{
|
207
|
-
|
207
|
+
fail "bad cookie? #{c.inspect}" unless /\A([^\s=]+)=([^\s=]+)\z/.match c.split(/\s*;\s*/).first
|
208
|
+
logger.debug "set-cookie: #{$1}=#{$2}"
|
209
|
+
old_cookies.delete $1
|
210
|
+
cookies.store $1, $2
|
211
|
+
end
|
212
|
+
old_cookies.each do |k, v|
|
213
|
+
logger.debug "faking an old cookie into new response: #{k}=#{v}"
|
214
|
+
response.add_field "Set-Cookie", "#{k}=#{v}"
|
208
215
|
end
|
209
216
|
case response.code
|
210
217
|
when /\A30\d\z/
|
@@ -267,7 +274,6 @@ module NetHTTPUtils
|
|
267
274
|
end
|
268
275
|
end
|
269
276
|
response = do_request.call prepare_request[uri]
|
270
|
-
cookies.each{ |k, v| response.add_field "Set-Cookie", "#{k}=#{v};" }
|
271
277
|
logger.debug "< header: #{response.to_hash}"
|
272
278
|
(response.body || "").tap{ |r| r.instance_variable_set :@last_response, response }
|
273
279
|
end
|
@@ -342,6 +348,25 @@ if $0 == __FILE__
|
|
342
348
|
require "json"
|
343
349
|
Thread.abort_on_exception = true
|
344
350
|
|
351
|
+
server = WEBrick::HTTPServer.new Port: 8000
|
352
|
+
server.mount_proc "/1" do |req, res|
|
353
|
+
next unless "GET" == req.request_method
|
354
|
+
res.cookies.push WEBrick::Cookie.new("1", "2")
|
355
|
+
res.cookies.push WEBrick::Cookie.new("3", "4")
|
356
|
+
res.cookies.push WEBrick::Cookie.new("1", "5")
|
357
|
+
res.status = 300
|
358
|
+
res["location"] = "/2"
|
359
|
+
end
|
360
|
+
server.mount_proc "/2" do |req, res|
|
361
|
+
res.cookies.push WEBrick::Cookie.new("3", "6")
|
362
|
+
res.cookies.push WEBrick::Cookie.new("4", "7")
|
363
|
+
end
|
364
|
+
t = Thread.new{ server.start }
|
365
|
+
fail unless %w{ 3=6 4=7 1=5 } == p(NetHTTPUtils.request_data("http://localhost:8000/1").
|
366
|
+
instance_variable_get(:@last_response).to_hash.fetch("set-cookie"))
|
367
|
+
server.shutdown
|
368
|
+
t.join
|
369
|
+
|
345
370
|
[
|
346
371
|
[WEBrick::HTTPStatus::NotFound, 404],
|
347
372
|
[WEBrick::HTTPStatus::BadRequest],
|
@@ -360,6 +385,7 @@ if $0 == __FILE__
|
|
360
385
|
fail unless 404 == e.code
|
361
386
|
end
|
362
387
|
server.shutdown
|
388
|
+
t.join
|
363
389
|
end
|
364
390
|
|
365
391
|
server = WEBrick::HTTPServer.new Port: 8000
|
@@ -380,12 +406,12 @@ if $0 == __FILE__
|
|
380
406
|
NetHTTPUtils.request_data("http://localhost:8000/")
|
381
407
|
fail stack.inspect unless stack == %w{ HEAD GET }
|
382
408
|
server.shutdown
|
409
|
+
t.join
|
383
410
|
|
384
411
|
# TODO: test that HEAD method request goes through redirects
|
385
412
|
# TODO: test for `NetHTTPUtils.request_data "...", :head
|
386
413
|
# TODO: request the HEAD only if mtd == :GET
|
387
414
|
|
388
|
-
t.join # Address already in use - bind(2) for [::]:8000 (Errno::EADDRINUSE)
|
389
415
|
server = WEBrick::HTTPServer.new Port: 8000
|
390
416
|
server.mount_proc ?/ do |req, res|
|
391
417
|
# pp req.dup.tap{ |_| _.instance_variable_set "@config", nil }
|
@@ -432,7 +458,6 @@ if $0 == __FILE__
|
|
432
458
|
end
|
433
459
|
end
|
434
460
|
%w{
|
435
|
-
http://minus.com/lkP3hgRJd9npi
|
436
461
|
http://www.cutehalloweencostumeideas.org/wp-content/uploads/2017/10/Niagara-Falls_04.jpg
|
437
462
|
}.each do |url|
|
438
463
|
begin
|
data/nethttputils.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "nethttputils"
|
3
|
-
spec.version = "0.3.2.
|
3
|
+
spec.version = "0.3.2.7"
|
4
4
|
spec.summary = "this tool is like a pet that I adopted young and now I depend on, sorry"
|
5
5
|
spec.description = <<-EOF
|
6
6
|
Back in 2015 I was a guy automating things at my job and two scripts had a common need --
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nethttputils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.2.
|
4
|
+
version: 0.3.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Back in 2015 I was a guy automating things at my job and two scripts had a common need --
|