dubdubdub 0.2.4 → 0.2.5
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.
- data/dubdubdub.gemspec +2 -1
- data/lib/dubdubdub.rb +1 -1
- data/lib/dubdubdub/client.rb +15 -2
- data/spec/dubdubdub_spec.rb +4 -0
- data/spec/vcr/follow_url/relative_redirects.yml +122 -0
- metadata +3 -2
data/dubdubdub.gemspec
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "dubdubdub"
|
|
8
|
-
s.version = "0.2.
|
|
8
|
+
s.version = "0.2.5"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["James Hu"]
|
|
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
|
|
|
43
43
|
"spec/vcr/follow_url/proxied.yml",
|
|
44
44
|
"spec/vcr/follow_url/proxy.yml",
|
|
45
45
|
"spec/vcr/follow_url/proxy_forbidden.yml",
|
|
46
|
+
"spec/vcr/follow_url/relative_redirects.yml",
|
|
46
47
|
"spec/vcr/get/basic.yml",
|
|
47
48
|
"spec/vcr/get/params.yml",
|
|
48
49
|
"spec/vcr/get/proxy.yml"
|
data/lib/dubdubdub.rb
CHANGED
data/lib/dubdubdub/client.rb
CHANGED
|
@@ -118,6 +118,7 @@ class DubDubDub::Client
|
|
|
118
118
|
options = default_options.merge(options)
|
|
119
119
|
|
|
120
120
|
at_base = false
|
|
121
|
+
previous_uri = nil # Keep track of previous uri for relative path redirects
|
|
121
122
|
response = nil
|
|
122
123
|
user_agents = [
|
|
123
124
|
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11',
|
|
@@ -172,16 +173,28 @@ class DubDubDub::Client
|
|
|
172
173
|
end
|
|
173
174
|
|
|
174
175
|
# If any of these exceptions get thrown, return the current url
|
|
175
|
-
rescue SocketError,
|
|
176
|
+
rescue SocketError, EOFError
|
|
176
177
|
at_base = true
|
|
178
|
+
rescue URI::InvalidURIError
|
|
179
|
+
return url # Just return it
|
|
177
180
|
end
|
|
178
181
|
|
|
179
182
|
urls << url
|
|
180
183
|
|
|
181
184
|
break if at_base
|
|
185
|
+
|
|
186
|
+
previous_uri = uri # Keep track of previous uri
|
|
182
187
|
yield(url) if block_given?
|
|
183
188
|
end
|
|
184
189
|
|
|
185
|
-
url
|
|
190
|
+
end_uri = URI.parse(url)
|
|
191
|
+
|
|
192
|
+
# If there is no host, it's due to a relative 301 redirect. Use previous uri's host, port, etc
|
|
193
|
+
if !end_uri.host and previous_uri
|
|
194
|
+
end_uri = previous_uri
|
|
195
|
+
end_uri.path = url
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
end_uri.to_s
|
|
186
199
|
end
|
|
187
200
|
end
|
data/spec/dubdubdub_spec.rb
CHANGED
|
@@ -230,6 +230,10 @@ describe DubDubDub do
|
|
|
230
230
|
www.follow_url("google.com").should == "google.com"
|
|
231
231
|
end
|
|
232
232
|
|
|
233
|
+
it "works with relative path redirects", vcr: { cassette_name: "follow_url/relative_redirects", record: :once } do
|
|
234
|
+
www.follow_url("http://www.retailmenot.com/out/4223117").should == "http://www.papajohns.com/index.html"
|
|
235
|
+
end
|
|
236
|
+
|
|
233
237
|
it "raises forbidden properly on a bad proxy", vcr: { cassette_name: "follow_url/proxy_forbidden", record: :once } do
|
|
234
238
|
www.proxy = "190.202.116.101:3128"
|
|
235
239
|
lambda { www.follow_url("http://yfrog.us/evlb0z:medium").should }.should raise_error(DubDubDub::Forbidden)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: http://www.retailmenot.com/out/4223117
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
accept:
|
|
11
|
+
- ! '*/*'
|
|
12
|
+
user-agent:
|
|
13
|
+
- Ruby
|
|
14
|
+
response:
|
|
15
|
+
status:
|
|
16
|
+
code: 302
|
|
17
|
+
message: Found
|
|
18
|
+
headers:
|
|
19
|
+
content-type:
|
|
20
|
+
- text/html; charset=utf-8
|
|
21
|
+
date:
|
|
22
|
+
- Tue, 04 Dec 2012 02:09:53 GMT
|
|
23
|
+
location:
|
|
24
|
+
- http://papajohns.com
|
|
25
|
+
server:
|
|
26
|
+
- nginx
|
|
27
|
+
set-cookie:
|
|
28
|
+
- cid=deleted; expires=Mon, 05-Dec-2011 02:09:59 GMT; path=/; domain=retailmenot.com
|
|
29
|
+
- ppage=deleted; expires=Mon, 05-Dec-2011 02:09:59 GMT; path=/; domain=retailmenot.com
|
|
30
|
+
- ouid=deleted; expires=Mon, 05-Dec-2011 02:09:59 GMT; path=/; domain=retailmenot.com
|
|
31
|
+
- ut=16388; expires=Tue, 18-Dec-2012 02:10:00 GMT; path=/; domain=retailmenot.com
|
|
32
|
+
- userFlashVersion=KI7ON5J5tS; expires=Sun, 03-Dec-2017 02:10:00 GMT; path=/;
|
|
33
|
+
domain=retailmenot.com
|
|
34
|
+
vary:
|
|
35
|
+
- Accept-Encoding
|
|
36
|
+
content-length:
|
|
37
|
+
- '0'
|
|
38
|
+
connection:
|
|
39
|
+
- Close
|
|
40
|
+
body:
|
|
41
|
+
encoding: US-ASCII
|
|
42
|
+
string: ''
|
|
43
|
+
http_version: '1.1'
|
|
44
|
+
recorded_at: Tue, 04 Dec 2012 02:09:53 GMT
|
|
45
|
+
- request:
|
|
46
|
+
method: get
|
|
47
|
+
uri: http://papajohns.com/
|
|
48
|
+
body:
|
|
49
|
+
encoding: US-ASCII
|
|
50
|
+
string: ''
|
|
51
|
+
headers:
|
|
52
|
+
accept:
|
|
53
|
+
- ! '*/*'
|
|
54
|
+
user-agent:
|
|
55
|
+
- Ruby
|
|
56
|
+
response:
|
|
57
|
+
status:
|
|
58
|
+
code: 301
|
|
59
|
+
message: Moved Permanently
|
|
60
|
+
headers:
|
|
61
|
+
server:
|
|
62
|
+
- AkamaiGHost
|
|
63
|
+
content-length:
|
|
64
|
+
- '0'
|
|
65
|
+
location:
|
|
66
|
+
- http://www.papajohns.com/
|
|
67
|
+
date:
|
|
68
|
+
- Tue, 04 Dec 2012 02:09:53 GMT
|
|
69
|
+
connection:
|
|
70
|
+
- close
|
|
71
|
+
body:
|
|
72
|
+
encoding: US-ASCII
|
|
73
|
+
string: ''
|
|
74
|
+
http_version: '1.1'
|
|
75
|
+
recorded_at: Tue, 04 Dec 2012 02:09:54 GMT
|
|
76
|
+
- request:
|
|
77
|
+
method: get
|
|
78
|
+
uri: http://www.papajohns.com/
|
|
79
|
+
body:
|
|
80
|
+
encoding: US-ASCII
|
|
81
|
+
string: ''
|
|
82
|
+
headers:
|
|
83
|
+
accept:
|
|
84
|
+
- ! '*/*'
|
|
85
|
+
user-agent:
|
|
86
|
+
- Ruby
|
|
87
|
+
response:
|
|
88
|
+
status:
|
|
89
|
+
code: 302
|
|
90
|
+
message: Moved Temporarily
|
|
91
|
+
headers:
|
|
92
|
+
server:
|
|
93
|
+
- Microsoft-IIS/6.0
|
|
94
|
+
x-powered-by:
|
|
95
|
+
- ASP.NET
|
|
96
|
+
location:
|
|
97
|
+
- /index.html
|
|
98
|
+
content-length:
|
|
99
|
+
- '132'
|
|
100
|
+
content-type:
|
|
101
|
+
- text/html
|
|
102
|
+
cache-control:
|
|
103
|
+
- private
|
|
104
|
+
vary:
|
|
105
|
+
- Accept-Encoding
|
|
106
|
+
date:
|
|
107
|
+
- Tue, 04 Dec 2012 02:09:54 GMT
|
|
108
|
+
connection:
|
|
109
|
+
- close
|
|
110
|
+
set-cookie:
|
|
111
|
+
- ASPSESSIONIDQCTDRBDC=HKLJKGECGKICNAAEFJPFIADI; path=/
|
|
112
|
+
- BIGipServerPRD_WEB_HTTP=2256924991.20480.0000; path=/
|
|
113
|
+
body:
|
|
114
|
+
encoding: US-ASCII
|
|
115
|
+
string: ! '<head><title>Object moved</title></head>
|
|
116
|
+
|
|
117
|
+
<body><h1>Object Moved</h1>This object may be found <a HREF="/index.html">here</a>.</body>
|
|
118
|
+
|
|
119
|
+
'
|
|
120
|
+
http_version: '1.1'
|
|
121
|
+
recorded_at: Tue, 04 Dec 2012 02:09:54 GMT
|
|
122
|
+
recorded_with: VCR 2.3.0
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dubdubdub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -189,6 +189,7 @@ files:
|
|
|
189
189
|
- spec/vcr/follow_url/proxied.yml
|
|
190
190
|
- spec/vcr/follow_url/proxy.yml
|
|
191
191
|
- spec/vcr/follow_url/proxy_forbidden.yml
|
|
192
|
+
- spec/vcr/follow_url/relative_redirects.yml
|
|
192
193
|
- spec/vcr/get/basic.yml
|
|
193
194
|
- spec/vcr/get/params.yml
|
|
194
195
|
- spec/vcr/get/proxy.yml
|
|
@@ -207,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
207
208
|
version: '0'
|
|
208
209
|
segments:
|
|
209
210
|
- 0
|
|
210
|
-
hash:
|
|
211
|
+
hash: 1311831286708000735
|
|
211
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
213
|
none: false
|
|
213
214
|
requirements:
|