nethttputils 0.2.4.2 → 0.2.5.0

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: 627f4578fd2379b3e4781a55a5531ae6e3be21c8
4
- data.tar.gz: 9223bdf1313f2d9b44636db775c7142d8544be16
3
+ metadata.gz: 7bbc2695cb20cfc4890ebbac97ed54ed93cfe7d3
4
+ data.tar.gz: bf55a158b9052a138a7c3f576e8a8b03f05790fa
5
5
  SHA512:
6
- metadata.gz: 10b2e6f4dc815161ff679e76f518a6217027638710376c09e6fa0c6db975f8480daff3166e9a775782a13ade622b2cfe4b8ec494df82d8a5c75696a9f0a07809
7
- data.tar.gz: f3d8f5a374bffd2df400ec4ea675186773a0f70ac33d4f11afd4b4618a296d5bf2ea1834ca63f4a4ec6f42155b5fe14d2f36c3e1fe51e095dffba4ae7cee2152
6
+ metadata.gz: a827b0b0fcea495ae07a172989cdf1081242f9b8a7a68957de380d2854e2f7f1a0ff645fe5e1f7982b328b759bea29ae1c817c292e5491df51ef46dad1bd3fa3
7
+ data.tar.gz: a64a7e7de953f7eb3fb719eeea5df12e9d69a245c2a824b8837c013b404029d23f077a16fbb8cf5d865ec6402dab825af600741b5fff71874fa3771443d654ac
data/lib/nethttputils.rb CHANGED
@@ -45,7 +45,7 @@ module NetHTTPUtils
45
45
 
46
46
  uri.query = URI.encode_www_form form if :GET == (mtd = mtd.upcase) && !form.empty?
47
47
  cookies = {}
48
- prepare_request = lambda do |uri|
48
+ prepare_request = lambda do |uri, mtd = :GET, form = {}|
49
49
  case mtd.upcase
50
50
  when :GET ; Net::HTTP::Get
51
51
  when :POST ; Net::HTTP::Post
@@ -56,7 +56,6 @@ module NetHTTPUtils
56
56
  end.new(uri).tap do |request| # somehow Get eats even raw url, not URI object
57
57
  patch_request.call uri, form, request if patch_request
58
58
  request.basic_auth *auth if auth
59
- request["cookie"] = [*request["cookie"], cookies.map{ |k, v| "#{k}=#{v}" }].join "; " unless cookies.empty?
60
59
  # pp Object.instance_method(:method).bind(request).call(:set_form).source_location
61
60
  if (mtd == :POST || mtd == :PATCH) && !form.empty?
62
61
  case type
@@ -72,6 +71,7 @@ module NetHTTPUtils
72
71
  end
73
72
  end
74
73
  header.each{ |k, v| request[k.to_s] = v }
74
+ request["cookie"] = [*request["cookie"], cookies.map{ |k, v| "#{k}=#{v}" }].join "; " unless cookies.empty?
75
75
 
76
76
  logger.info "> #{request.class} #{uri.host} #{request.path}"
77
77
  next unless logger.debug?
@@ -191,7 +191,12 @@ module NetHTTPUtils
191
191
  end
192
192
  end
193
193
 
194
- response.to_hash.fetch("set-cookie", []).each{ |c| k, v = c.split(?=); cookies[k] = v[/[^;]+/] }
194
+ response.to_hash.fetch("set-cookie", []).each do |c|
195
+ k, v = c.split(?=)
196
+ logger.debug "set-cookie: #{k}=#{v[/[^;]+/]}"
197
+ cookies.store k, v[/[^;]+/]
198
+ end
199
+ logger.debug "< header: #{response.to_hash}"
195
200
  case response.code
196
201
  when /\A3\d\d\z/
197
202
  logger.info "redirect: #{response["location"]}"
@@ -236,7 +241,6 @@ module NetHTTPUtils
236
241
  } from #{
237
242
  [__FILE__, caller.map{ |i| i[/(?<=:)\d+/] }].join ?:
238
243
  }"
239
- logger.debug "< header: #{response.to_hash}"
240
244
  logger.debug "< body: #{
241
245
  response.body.tap do |body|
242
246
  body.replace remove_tags body if body[/<html[> ]/]
@@ -245,7 +249,7 @@ module NetHTTPUtils
245
249
  response
246
250
  end
247
251
  end
248
- do_request[prepare_request[uri]].tap do |response|
252
+ do_request[prepare_request[uri, mtd, form]].tap do |response|
249
253
  cookies.each{ |k, v| response.add_field "Set-Cookie", "#{k}=#{v};" }
250
254
  logger.debug "< header: #{response.to_hash}"
251
255
  end
@@ -263,6 +267,7 @@ module NetHTTPUtils
263
267
  response.body
264
268
  end.tap do |string|
265
269
  string.instance_variable_set :@uri_path, response.uri.path
270
+ string.instance_variable_set :@header, response.to_hash
266
271
  end
267
272
  # ensure
268
273
  # response.instance_variable_get("@nethttputils_close").call if response
data/nethttputils.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "nethttputils"
3
- spec.version = "0.2.4.2"
3
+ spec.version = "0.2.5.0"
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.2.4.2
4
+ version: 0.2.5.0
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: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2018-10-24 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 --
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  version: '0'
52
52
  requirements: []
53
53
  rubyforge_project:
54
- rubygems_version: 2.5.2
54
+ rubygems_version: 2.6.14
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: this tool is like a pet that I adopted young and now I depend on, sorry