nethttputils 0.3.2.6 → 0.3.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba824c7599a1d7d935dfd5c9bcc01c991201211e
4
- data.tar.gz: f6a5d7a00cc2a7f167562721b43ffa5df8ad0130
3
+ metadata.gz: 5ef478ad663a8500e057309f2fcb9bb3587a2525
4
+ data.tar.gz: 82ccf697e5a37a3d7a46a216ece1e1d5a0498e8f
5
5
  SHA512:
6
- metadata.gz: e973a3584da011dc3ef82c376d72dee3b665fae76660efd6c4e0bb7c9133b3aa146083ed96f9df81492134b98893e32fed797728dac0ac0e222d456573aabc2c
7
- data.tar.gz: b4faeeaf94da3a2c7bc614a16682aa7f8cf17c5ba1eb20eecf31f3d588d03d43eaaaf90dc9ef73dc089807a67a5572d97139efaf430f1289171ad6a80bdc3811
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
- k, v = c.split(?=)
206
- logger.debug "set-cookie: #{k}=#{v[/[^;]+/]}"
207
- cookies.store k, v[/[^;]+/]
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.6"
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.6
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-02-24 00:00:00.000000000 Z
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 --