pincers 0.7.7 → 0.7.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6da332a1a2cd06206a29878abce0860c7dd9714a
4
- data.tar.gz: 77a17252be6f58e1e76adcd04158c2ce94c3cbd3
3
+ metadata.gz: 4526e8ccc6d3ead10746ee9d7e95e473d063c467
4
+ data.tar.gz: 70fc43f5a6664ccbef9b0235db56e22065472882
5
5
  SHA512:
6
- metadata.gz: e34c26b569947c44307c280864268f6e7cbe855f35c9c265b188ef585a87d96e98b82973fc05230b679fbdbfb93c7a7bb9a95e688b55f7df4dd889ae0d5a34ec
7
- data.tar.gz: 01c3d5999f23c5351a14aaeab86a516d11006f8f93ec963af24d6a5c39e655d9ea422c9808a949d10ab5a27acee83842feb0cd3e8dede0aff6e8c2aadbd7d7ca
6
+ metadata.gz: 2ed5d778279256c922d66d71f763849edfc99f7060d818365a7ea73ffae06c5e3f7adf724d77021a05babd234f611e54c3898b657128f97a2ba81012acfc40f8
7
+ data.tar.gz: a911e5c4a3cb633f16308e6c03b4b27501f5241a0d2a1261a04e2f8d1e7acbb9df7e716f7aa2401874695a2c10032e334350c98e613b8bd70c5a2f01f8236394
@@ -1,8 +1,7 @@
1
1
  module Pincers::Http
2
2
  class Request
3
3
 
4
- attr_reader :method, :uri, :headers
5
- attr_accessor :data
4
+ attr_accessor :method, :uri, :data, :headers
6
5
 
7
6
  def initialize(_method, _uri)
8
7
  @method = _method
@@ -51,6 +50,17 @@ module Pincers::Http
51
50
  end
52
51
  end
53
52
 
53
+ def clone_for_redirect(_location, _repeat = true)
54
+ clone = self.class.new(_repeat ? method : :get, _location)
55
+
56
+ if _repeat
57
+ clone.headers = clone.headers.clone
58
+ clone.data = data
59
+ end
60
+
61
+ clone
62
+ end
63
+
54
64
  private
55
65
 
56
66
  def default_encoding_for(_pairs)
@@ -59,4 +69,4 @@ module Pincers::Http
59
69
  end
60
70
 
61
71
  end
62
- end
72
+ end
@@ -45,15 +45,15 @@ module Pincers::Http
45
45
  end
46
46
 
47
47
  def perform(_request)
48
- perform_recursive _request, @redirect_limit, nil
48
+ perform_recursive _request, @redirect_limit
49
49
  end
50
50
 
51
51
  private
52
52
 
53
- def perform_recursive(_request, _limit, _redirect)
53
+ def perform_recursive(_request, _limit)
54
54
  raise MaximumRedirectsError.new if _limit == 0
55
55
 
56
- uri = _redirect || _request.uri
56
+ uri = _request.uri
57
57
  path = uri.request_uri.empty? ? '/' : uri.request_uri
58
58
 
59
59
  http_request = _request.native_type.new path
@@ -72,12 +72,17 @@ module Pincers::Http
72
72
  when Net::HTTPRedirection
73
73
  location = Utils.parse_uri(http_response['location'])
74
74
  location = URI.join(uri, location) if location.relative?
75
- perform_recursive(_request, _limit - 1, location)
75
+ new_request = _request.clone_for_redirect(location, repeating_redirect?(http_response))
76
+ perform_recursive(new_request, _limit - 1)
76
77
  else
77
78
  handle_error_response Response.new(uri, http_response)
78
79
  end
79
80
  end
80
81
 
82
+ def repeating_redirect?(_req)
83
+ ["307", "308"].include?(_req.code)
84
+ end
85
+
81
86
  def connect(_uri)
82
87
  conn = Net::HTTP.new _uri.host, _uri.port || 80, @proxy_addr, @proxy_port
83
88
  conn.use_ssl = true if _uri.scheme == 'https'
@@ -1,3 +1,3 @@
1
1
  module Pincers
2
- VERSION = "0.7.7"
2
+ VERSION = "0.7.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pincers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-20 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  version: '0'
289
289
  requirements: []
290
290
  rubyforge_project:
291
- rubygems_version: 2.4.8
291
+ rubygems_version: 2.6.1
292
292
  signing_key:
293
293
  specification_version: 4
294
294
  summary: Web automation framework with multiple backend support