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 +4 -4
- data/Gemfile.lock +34 -27
- data/aitch.gemspec +0 -1
- data/lib/aitch.rb +1 -0
- data/lib/aitch/location.rb +26 -0
- data/lib/aitch/request.rb +5 -1
- data/lib/aitch/response.rb +1 -0
- data/lib/aitch/version.rb +1 -1
- data/spec/aitch/request_spec.rb +5 -2
- data/spec/aitch/response_spec.rb +21 -0
- metadata +26 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74de1f797705e033d093d57165a479c6b98f4586
|
4
|
+
data.tar.gz: ccad13b73ffdc1e648c666cbbb6d8fad162e08c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1849671f3d88abcee256d31d6200d7ce7831eebdc750fe272fdc75023faf20bfd048cc7cb5e32edf9a8c064abc3037f50f49f1f95b4b971cf0f18c86c44b5730
|
7
|
+
data.tar.gz: e4eac1e14d9a4a6a998c26cd3d33b32e2d349db37ef39cde837208407f834ca938af125ca6974d77e95c48043a1ac6a58458c5313e4a0268e4823f81b9b185e7
|
data/Gemfile.lock
CHANGED
@@ -1,61 +1,69 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aitch (0.
|
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.
|
12
|
-
i18n (~> 0.6, >= 0.6.
|
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.
|
18
|
-
awesome_print (1.
|
19
|
-
coderay (1.0
|
20
|
-
|
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.
|
29
|
+
i18n (0.6.9)
|
23
30
|
method_source (0.8.2)
|
24
|
-
mini_portile (0.5.
|
31
|
+
mini_portile (0.5.3)
|
25
32
|
minitest (4.7.5)
|
26
|
-
multi_json (1.
|
27
|
-
nokogiri (1.6.
|
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.
|
31
|
-
coderay (~> 1.0
|
37
|
+
pry (0.9.12.6)
|
38
|
+
coderay (~> 1.0)
|
32
39
|
method_source (~> 0.8)
|
33
40
|
slop (~> 3.4)
|
34
|
-
pry-
|
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-
|
47
|
+
pry-debugger
|
38
48
|
pry-remote
|
39
|
-
pry-
|
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.
|
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.
|
50
|
-
rspec-expectations (2.14.
|
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.
|
53
|
-
slop (3.
|
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
|
57
|
-
atomic
|
58
|
-
tzinfo (0.3.
|
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
|
data/aitch.gemspec
CHANGED
data/lib/aitch.rb
CHANGED
@@ -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
|
data/lib/aitch/request.rb
CHANGED
@@ -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(
|
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
|
data/lib/aitch/response.rb
CHANGED
data/lib/aitch/version.rb
CHANGED
data/spec/aitch/request_spec.rb
CHANGED
@@ -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/",
|
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
|
data/spec/aitch/response_spec.rb
CHANGED
@@ -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.
|
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:
|
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.
|
190
|
+
rubygems_version: 2.2.2
|
204
191
|
signing_key:
|
205
192
|
specification_version: 4
|
206
193
|
summary: A simple HTTP client
|