aitch 0.2.1 → 0.3.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: 9fe92f9a37fda506090a65c10f58d0f1c404de82
4
- data.tar.gz: e4802e77177c7b5da355d90861648c457af07baf
3
+ metadata.gz: 74de1f797705e033d093d57165a479c6b98f4586
4
+ data.tar.gz: ccad13b73ffdc1e648c666cbbb6d8fad162e08c8
5
5
  SHA512:
6
- metadata.gz: 8a30b1ca7591ba25d71ee744500f8aee14bb53b518b3f00011eed86fec098b5f3d10d79992a692cc777233e787acc5b599b0d5050bcd640e2262309eb5032d97
7
- data.tar.gz: 86f02583bf0a48e299115d5c4724e8f098074e4244c6ff0693cf56cbdcfbc8e3f88398b3a8f71e54bc20636a1925de7db399aed5d2266ccc6c926dd18952cff9
6
+ metadata.gz: 1849671f3d88abcee256d31d6200d7ce7831eebdc750fe272fdc75023faf20bfd048cc7cb5e32edf9a8c064abc3037f50f49f1f95b4b971cf0f18c86c44b5730
7
+ data.tar.gz: e4eac1e14d9a4a6a998c26cd3d33b32e2d349db37ef39cde837208407f834ca938af125ca6974d77e95c48043a1ac6a58458c5313e4a0268e4823f81b9b185e7
@@ -1,61 +1,69 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aitch (0.2.1)
4
+ aitch (0.3.0)
5
5
  activesupport
6
6
  nokogiri (>= 1.6.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (4.0.0)
12
- i18n (~> 0.6, >= 0.6.4)
11
+ activesupport (4.0.4)
12
+ i18n (~> 0.6, >= 0.6.9)
13
13
  minitest (~> 4.2)
14
14
  multi_json (~> 1.3)
15
15
  thread_safe (~> 0.1)
16
16
  tzinfo (~> 0.3.37)
17
- atomic (1.1.10)
18
- awesome_print (1.1.0)
19
- coderay (1.0.9)
20
- diff-lcs (1.2.4)
17
+ atomic (1.1.16)
18
+ awesome_print (1.2.0)
19
+ coderay (1.1.0)
20
+ columnize (0.3.6)
21
+ debugger (1.6.6)
22
+ columnize (>= 0.3.1)
23
+ debugger-linecache (~> 1.2.0)
24
+ debugger-ruby_core_source (~> 1.3.2)
25
+ debugger-linecache (1.2.0)
26
+ debugger-ruby_core_source (1.3.2)
27
+ diff-lcs (1.2.5)
21
28
  fakeweb (1.3.0)
22
- i18n (0.6.4)
29
+ i18n (0.6.9)
23
30
  method_source (0.8.2)
24
- mini_portile (0.5.1)
31
+ mini_portile (0.5.3)
25
32
  minitest (4.7.5)
26
- multi_json (1.7.7)
27
- nokogiri (1.6.0)
33
+ multi_json (1.9.2)
34
+ nokogiri (1.6.1)
28
35
  mini_portile (~> 0.5.0)
29
36
  notifier (0.4.1)
30
- pry (0.9.12.2)
31
- coderay (~> 1.0.5)
37
+ pry (0.9.12.6)
38
+ coderay (~> 1.0)
32
39
  method_source (~> 0.8)
33
40
  slop (~> 3.4)
34
- pry-meta (0.0.5)
41
+ pry-debugger (0.2.2)
42
+ debugger (~> 1.3)
43
+ pry (~> 0.9.10)
44
+ pry-meta (0.0.6)
35
45
  awesome_print
36
46
  pry
37
- pry-nav
47
+ pry-debugger
38
48
  pry-remote
39
- pry-nav (0.2.3)
40
- pry (~> 0.9.10)
41
- pry-remote (0.1.7)
49
+ pry-remote (0.1.8)
42
50
  pry (~> 0.9)
43
51
  slop (~> 3.0)
44
- rake (10.1.0)
52
+ rake (10.2.2)
45
53
  rspec (2.14.1)
46
54
  rspec-core (~> 2.14.0)
47
55
  rspec-expectations (~> 2.14.0)
48
56
  rspec-mocks (~> 2.14.0)
49
- rspec-core (2.14.4)
50
- rspec-expectations (2.14.0)
57
+ rspec-core (2.14.8)
58
+ rspec-expectations (2.14.5)
51
59
  diff-lcs (>= 1.1.3, < 2.0)
52
- rspec-mocks (2.14.1)
53
- slop (3.4.6)
60
+ rspec-mocks (2.14.6)
61
+ slop (3.5.0)
54
62
  test_notifier (1.0.1)
55
63
  notifier
56
- thread_safe (0.1.2)
57
- atomic
58
- tzinfo (0.3.37)
64
+ thread_safe (0.3.1)
65
+ atomic (>= 1.1.7, < 2)
66
+ tzinfo (0.3.39)
59
67
 
60
68
  PLATFORMS
61
69
  ruby
@@ -64,7 +72,6 @@ DEPENDENCIES
64
72
  aitch!
65
73
  bundler
66
74
  fakeweb
67
- nokogiri
68
75
  pry-meta
69
76
  rake
70
77
  rspec
@@ -27,5 +27,4 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "pry-meta"
28
28
  spec.add_development_dependency "test_notifier"
29
29
  spec.add_development_dependency "fakeweb"
30
- spec.add_development_dependency "nokogiri"
31
30
  end
@@ -10,6 +10,7 @@ require "aitch/utils"
10
10
  require "aitch/uri"
11
11
  require "aitch/dsl"
12
12
  require "aitch/namespace"
13
+ require "aitch/location"
13
14
  require "aitch/configuration"
14
15
  require "aitch/errors"
15
16
  require "aitch/request"
@@ -0,0 +1,26 @@
1
+ module Aitch
2
+ class Location
3
+ attr_reader :redirect_stack, :current_url
4
+
5
+ def initialize(redirect_stack, current_url)
6
+ @redirect_stack = redirect_stack
7
+ @current_url = current_url
8
+ end
9
+
10
+ def location
11
+ return current_url unless current_url.match(%r[\A/])
12
+
13
+ uri = find_uri_with_host
14
+ url = "#{uri.scheme}://#{uri.hostname}"
15
+ url << ":#{uri.port}" unless [80, 443].include?(uri.port)
16
+ url << current_url
17
+ url
18
+ end
19
+
20
+ def find_uri_with_host
21
+ redirect_stack.reverse
22
+ .map {|url| ::URI.parse(url) }
23
+ .find {|uri| uri.scheme }
24
+ end
25
+ end
26
+ end
@@ -17,15 +17,19 @@ module Aitch
17
17
 
18
18
  def perform
19
19
  response = Response.new(options, client.request(request))
20
+ response.url = url
20
21
  redirect = Redirect.new(options)
21
22
 
22
23
  while redirect.follow?(response)
24
+ redirected_from ||= [url]
25
+ redirected_from << Location.new(redirected_from, response.location).location
23
26
  redirect.followed!
24
- response = Aitch.get(response.location)
27
+ response = Aitch.get(redirected_from.last)
25
28
  end
26
29
 
27
30
  raise TooManyRedirectsError if redirect.enabled? && response.redirect?
28
31
 
32
+ response.redirected_from = redirected_from
29
33
  response
30
34
  rescue timeout_exception
31
35
  raise RequestTimeoutError
@@ -3,6 +3,7 @@ module Aitch
3
3
  extend Forwardable
4
4
 
5
5
  def_delegators :@http_response, :content_type
6
+ attr_accessor :redirected_from, :url
6
7
 
7
8
  def initialize(options, http_response)
8
9
  @options = options
@@ -1,3 +1,3 @@
1
1
  module Aitch
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -155,12 +155,15 @@ describe Aitch::Request do
155
155
  Aitch.configuration.redirect_limit = 5
156
156
 
157
157
  FakeWeb.register_uri(:get, "http://example.org/", location: "http://example.com/", status: 301)
158
- FakeWeb.register_uri(:get, "http://example.com/", body: "Hello")
158
+ FakeWeb.register_uri(:get, "http://example.com/", location: "http://www.example.com/", status: 301)
159
+ FakeWeb.register_uri(:get, "http://www.example.com/", body: "Hello")
159
160
 
160
- response = Aitch.get("http://example.org")
161
+ response = Aitch.get("http://example.org/")
161
162
 
162
163
  expect(response).not_to be_redirect
163
164
  expect(response.body).to eql("Hello")
165
+ expect(response.redirected_from).to eql(["http://example.org/", "http://example.com/"])
166
+ expect(response.url).to eql("http://www.example.com/")
164
167
  end
165
168
 
166
169
  it "raises when doing too many redirects" do
@@ -7,6 +7,12 @@ describe Aitch::Response do
7
7
  expect(response.body).to eql("Hello")
8
8
  end
9
9
 
10
+ it "sets current url" do
11
+ FakeWeb.register_uri(:get, "http://example.org/", body: "Hello")
12
+ response = Aitch.get("http://example.org/")
13
+ expect(response.url).to eql("http://example.org/")
14
+ end
15
+
10
16
  it "parses gzip response" do
11
17
  stdio = StringIO.new
12
18
  gzipped = Zlib::GzipWriter.new(stdio)
@@ -98,6 +104,21 @@ describe Aitch::Response do
98
104
  response = Aitch.get("http://example.org/")
99
105
  expect(response.location).to eql("https://example.com/")
100
106
  end
107
+
108
+ it "follows absolute paths" do
109
+ Aitch.configuration.follow_redirect = true
110
+ Aitch.configuration.redirect_limit = 5
111
+
112
+ FakeWeb.register_uri(:get, "http://example.org/", status: 301, location: "/hello")
113
+ FakeWeb.register_uri(:get, "http://example.org/hello", status: 301, location: "/hi")
114
+ FakeWeb.register_uri(:get, "http://example.org/hi", status: 200, body: "Hi")
115
+
116
+ response = Aitch.get("http://example.org/")
117
+
118
+ expect(response.redirected_from).to eql(["http://example.org/", "http://example.org/hello"])
119
+ expect(response.url).to eql("http://example.org/hi")
120
+ expect(response.body).to eql("Hi")
121
+ end
101
122
  end
102
123
 
103
124
  context "status 4xx" do
metadata CHANGED
@@ -1,139 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-30 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry-meta
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: test_notifier
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: fakeweb
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: nokogiri
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '>='
122
+ - - ">="
137
123
  - !ruby/object:Gem::Version
138
124
  version: '0'
139
125
  description: A simple HTTP client
@@ -143,10 +129,10 @@ executables: []
143
129
  extensions: []
144
130
  extra_rdoc_files: []
145
131
  files:
146
- - .coveralls.yml
147
- - .gitignore
148
- - .rspec
149
- - .travis.yml
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
150
136
  - Gemfile
151
137
  - Gemfile.lock
152
138
  - LICENSE.txt
@@ -158,6 +144,7 @@ files:
158
144
  - lib/aitch/dsl.rb
159
145
  - lib/aitch/errors.rb
160
146
  - lib/aitch/html_parser.rb
147
+ - lib/aitch/location.rb
161
148
  - lib/aitch/namespace.rb
162
149
  - lib/aitch/redirect.rb
163
150
  - lib/aitch/request.rb
@@ -190,17 +177,17 @@ require_paths:
190
177
  - lib
191
178
  required_ruby_version: !ruby/object:Gem::Requirement
192
179
  requirements:
193
- - - '>='
180
+ - - ">="
194
181
  - !ruby/object:Gem::Version
195
182
  version: '0'
196
183
  required_rubygems_version: !ruby/object:Gem::Requirement
197
184
  requirements:
198
- - - '>='
185
+ - - ">="
199
186
  - !ruby/object:Gem::Version
200
187
  version: '0'
201
188
  requirements: []
202
189
  rubyforge_project:
203
- rubygems_version: 2.0.3
190
+ rubygems_version: 2.2.2
204
191
  signing_key:
205
192
  specification_version: 4
206
193
  summary: A simple HTTP client