nethttputils 0.4.1.3 → 0.4.2.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: aa8c5d5ae78a7dbad64fe4d0e624666cfcbe1642
4
- data.tar.gz: 8d09dcf215b50515dc6033f5ef6b6760f14c844c
3
+ metadata.gz: 6b310f69be9a582878a60741eb385b2cbc61884b
4
+ data.tar.gz: fee129582c51e0ec02abc63e318a681534edc391
5
5
  SHA512:
6
- metadata.gz: c315180c06335286428ffb1aff4c41ba6b1648644dc2c41b3f199c8fe2102238e0323359590bb74db31b487e4499b27c5d9823c0a300bae1eafe9f114a62cc59
7
- data.tar.gz: 07b47969d1d87ffd4bdd409b038aef316b770f5d3b4d00d7ad0faa419ac559dfa362548c5f942df3300629a6ba9f5ef630370412e73a80afaef785dfde938bb3
6
+ metadata.gz: d7f628d6558dbe9aa0d08125c5a294c957235858829013ac4dd655b0b28fc63e38bed1827ce35fbb9de1d66ca6acde828fa3a5d77ea90a3e08238751cab9b0ea
7
+ data.tar.gz: ea174acf8e166ef034d6d151b171babdb19fa3736cd23fbdb006c460deb28236f1ce33c1bbc72194d30695498ccc1292108063b6319b54eace9631a5b3e68bc7
data/lib/nethttputils.rb CHANGED
@@ -101,15 +101,17 @@ module NetHTTPUtils
101
101
  end
102
102
 
103
103
  private
104
- def read http, mtd = :GET, type = :form, form: {}, header: {}, auth: nil, timeout: nil, no_redirect: false, max_read_retry_delay: 3600, patch_request: nil, &block
104
+ def read http, mtd = :GET, type = :form, form: {}, header: {}, auth: nil, force_post: false, timeout: nil, no_redirect: false, max_read_retry_delay: 3600, patch_request: nil, &block
105
105
  timeout ||= 30
106
- logger = NetHTTPUtils.logger
106
+ logger = NetHTTPUtils.logger
107
+ logger.info [mtd, http].inspect
107
108
 
108
109
  uri = http.instance_variable_get :@uri
109
- logger.debug "Warning: query params included in `url` argument are discarded because `:form` isn't empty" if uri.query && !form.empty?
110
+ if %i{ HEAD GET }.include?(mtd = mtd.upcase) && !form.empty? # not .upcase! because it's not defined for Symbol
111
+ logger.debug "Warning: query params included in `url` argument are discarded because `:form` isn't empty" if uri.query
110
112
  # we can't just merge because URI fails to parse such queries as "/?1"
111
-
112
- uri.query = URI.encode_www_form form if %i{ HEAD GET }.include?(mtd = mtd.upcase) && !form.empty?
113
+ uri.query = URI.encode_www_form form
114
+ end
113
115
  cookies = {}
114
116
  prepare_request = lambda do |uri|
115
117
  case mtd.upcase
@@ -233,6 +235,7 @@ module NetHTTPUtils
233
235
  response.add_field "Set-Cookie", "#{k}=#{v}"
234
236
  end
235
237
 
238
+ logger.info "response.code = #{response.code}"
236
239
  case response.code
237
240
  when /\A20/
238
241
  response
@@ -250,8 +253,8 @@ module NetHTTPUtils
250
253
  # http.finish # why commented out?
251
254
  http = NetHTTPUtils.start_http new_uri, http.instance_variable_get(:@max_start_http_retry_delay), timeout, no_redirect
252
255
  end
253
- if request.method == "POST"
254
- logger.info "POST redirects to GET (RFC)"
256
+ if !force_post && request.method == "POST"
257
+ logger.info "POST redirects to GET (RFC)" # TODO: do it only on code 307; note that some servers still do 302
255
258
  mtd = :GET
256
259
  end
257
260
  do_request.call prepare_request[new_uri]
@@ -285,8 +288,9 @@ module NetHTTPUtils
285
288
  }"
286
289
  response
287
290
  else
288
- logger.warn "code #{response.code} at #{request.method} #{request.uri} from #{
289
- [__FILE__, caller.map{ |i| i[/(?<=:)\d+/] }].join ?:
291
+ logger.warn "code #{response.code} from #{request.method} #{request.uri} at #{
292
+ caller_path, caller_locs = caller_locations.chunk(&:path).first
293
+ [caller_path, caller_locs.map(&:lineno).chunk(&:itself).map(&:first)].join ":"
290
294
  }"
291
295
  logger.debug "< body: #{
292
296
  response.body.tap do |body|
@@ -304,7 +308,7 @@ module NetHTTPUtils
304
308
 
305
309
  require "set"
306
310
  @@_405 ||= Set.new
307
- def request_data http, mtd = :GET, type = :form, form: {}, header: {}, auth: nil, proxy: nil,
311
+ def request_data http, mtd = :GET, type = :form, form: {}, header: {}, auth: nil, proxy: nil, force_post: false,
308
312
  timeout: nil, no_redirect: false,
309
313
  max_start_http_retry_delay: 3600,
310
314
  max_read_retry_delay: 3600,
@@ -341,7 +345,7 @@ module NetHTTPUtils
341
345
  check_code.call body
342
346
  end
343
347
  end
344
- body = read http, mtd, type, form: form, header: header, auth: auth,
348
+ body = read http, mtd, type, form: form, header: header, auth: auth, force_post: force_post,
345
349
  timeout: timeout, no_redirect: no_redirect,
346
350
  max_read_retry_delay: max_read_retry_delay,
347
351
  patch_request: patch_request, &block
@@ -352,7 +356,6 @@ module NetHTTPUtils
352
356
  Zlib::GzipReader.new(StringIO.new(body)).read
353
357
  else
354
358
  body
355
- end.tap do |string|
356
359
  end
357
360
  # ensure
358
361
  # 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.4.1.3"
3
+ spec.version = "0.4.2.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.4.1.3
4
+ version: 0.4.2.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: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable