frameworks-capybara 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGES +6 -0
- data/Gemfile +0 -6
- data/Gemfile.lock +18 -31
- data/README.rdoc +0 -3
- data/frameworks-capybara.gemspec +7 -12
- data/lib/{monkey-patches/capybara-mechanize-patches.rb → extensions/capybara-mechanize-extensions.rb} +2 -33
- data/lib/frameworks/capybara.rb +13 -22
- data/lib/frameworks/cucumber.rb +0 -16
- data/lib/version.rb +1 -1
- data/spec/frameworks_capybara_spec.rb +5 -51
- data/spec/spec_helper.rb +0 -1
- data/spec/unit_test_monkeypatches.rb +3 -0
- metadata +13 -132
- data/lib/monkey-patches/capybara-patches.rb +0 -89
- data/lib/monkey-patches/cucumber-patches.rb +0 -51
- data/lib/monkey-patches/mechanize-patches.rb +0 -180
- data/lib/monkey-patches/net-http-persistent-patches.rb +0 -72
- data/lib/monkey-patches/send-keys.rb +0 -69
- data/lib/monkey-patches/webdriver-patches.rb +0 -61
- data/spec/capybara_mechanize_patches_spec.rb +0 -124
metadata
CHANGED
@@ -1,36 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frameworks-capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- matt robbins
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: nokogiri
|
14
|
+
name: selenium-webdriver
|
32
15
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
16
|
requirements:
|
35
17
|
- - ! '>='
|
36
18
|
- !ruby/object:Gem::Version
|
@@ -38,15 +20,13 @@ dependencies:
|
|
38
20
|
type: :runtime
|
39
21
|
prerelease: false
|
40
22
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
23
|
requirements:
|
43
24
|
- - ! '>='
|
44
25
|
- !ruby/object:Gem::Version
|
45
26
|
version: '0'
|
46
27
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
28
|
+
name: capybara
|
48
29
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
30
|
requirements:
|
51
31
|
- - ! '>='
|
52
32
|
- !ruby/object:Gem::Version
|
@@ -54,15 +34,13 @@ dependencies:
|
|
54
34
|
type: :runtime
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
37
|
requirements:
|
59
38
|
- - ! '>='
|
60
39
|
- !ruby/object:Gem::Version
|
61
40
|
version: '0'
|
62
41
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
42
|
+
name: mechanize
|
64
43
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
44
|
requirements:
|
67
45
|
- - ! '>='
|
68
46
|
- !ruby/object:Gem::Version
|
@@ -70,69 +48,13 @@ dependencies:
|
|
70
48
|
type: :runtime
|
71
49
|
prerelease: false
|
72
50
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
51
|
requirements:
|
75
52
|
- - ! '>='
|
76
53
|
- !ruby/object:Gem::Version
|
77
54
|
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: capybara
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ~>
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 1.1.2
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ~>
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 1.1.2
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: mechanize
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - '='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 2.7.2
|
102
|
-
type: :runtime
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - '='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 2.7.2
|
110
55
|
- !ruby/object:Gem::Dependency
|
111
56
|
name: capybara-mechanize
|
112
57
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.3.0
|
118
|
-
- - <
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version: 1.0.0
|
121
|
-
type: :runtime
|
122
|
-
prerelease: false
|
123
|
-
version_requirements: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
|
-
requirements:
|
126
|
-
- - ! '>='
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
version: 0.3.0
|
129
|
-
- - <
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 1.0.0
|
132
|
-
- !ruby/object:Gem::Dependency
|
133
|
-
name: json
|
134
|
-
requirement: !ruby/object:Gem::Requirement
|
135
|
-
none: false
|
136
58
|
requirements:
|
137
59
|
- - ! '>='
|
138
60
|
- !ruby/object:Gem::Version
|
@@ -140,15 +62,13 @@ dependencies:
|
|
140
62
|
type: :runtime
|
141
63
|
prerelease: false
|
142
64
|
version_requirements: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
65
|
requirements:
|
145
66
|
- - ! '>='
|
146
67
|
- !ruby/object:Gem::Version
|
147
68
|
version: '0'
|
148
69
|
- !ruby/object:Gem::Dependency
|
149
|
-
name:
|
70
|
+
name: json
|
150
71
|
requirement: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
72
|
requirements:
|
153
73
|
- - ! '>='
|
154
74
|
- !ruby/object:Gem::Version
|
@@ -156,15 +76,13 @@ dependencies:
|
|
156
76
|
type: :runtime
|
157
77
|
prerelease: false
|
158
78
|
version_requirements: !ruby/object:Gem::Requirement
|
159
|
-
none: false
|
160
79
|
requirements:
|
161
80
|
- - ! '>='
|
162
81
|
- !ruby/object:Gem::Version
|
163
82
|
version: '0'
|
164
83
|
- !ruby/object:Gem::Dependency
|
165
|
-
name:
|
84
|
+
name: cucumber
|
166
85
|
requirement: !ruby/object:Gem::Requirement
|
167
|
-
none: false
|
168
86
|
requirements:
|
169
87
|
- - ! '>='
|
170
88
|
- !ruby/object:Gem::Version
|
@@ -172,7 +90,6 @@ dependencies:
|
|
172
90
|
type: :runtime
|
173
91
|
prerelease: false
|
174
92
|
version_requirements: !ruby/object:Gem::Requirement
|
175
|
-
none: false
|
176
93
|
requirements:
|
177
94
|
- - ! '>='
|
178
95
|
- !ruby/object:Gem::Version
|
@@ -180,7 +97,6 @@ dependencies:
|
|
180
97
|
- !ruby/object:Gem::Dependency
|
181
98
|
name: w3c_validators
|
182
99
|
requirement: !ruby/object:Gem::Requirement
|
183
|
-
none: false
|
184
100
|
requirements:
|
185
101
|
- - ! '>='
|
186
102
|
- !ruby/object:Gem::Version
|
@@ -188,31 +104,13 @@ dependencies:
|
|
188
104
|
type: :runtime
|
189
105
|
prerelease: false
|
190
106
|
version_requirements: !ruby/object:Gem::Requirement
|
191
|
-
none: false
|
192
107
|
requirements:
|
193
108
|
- - ! '>='
|
194
109
|
- !ruby/object:Gem::Version
|
195
110
|
version: '0'
|
196
|
-
- !ruby/object:Gem::Dependency
|
197
|
-
name: cucumber
|
198
|
-
requirement: !ruby/object:Gem::Requirement
|
199
|
-
none: false
|
200
|
-
requirements:
|
201
|
-
- - ! '>='
|
202
|
-
- !ruby/object:Gem::Version
|
203
|
-
version: 0.10.5
|
204
|
-
type: :runtime
|
205
|
-
prerelease: false
|
206
|
-
version_requirements: !ruby/object:Gem::Requirement
|
207
|
-
none: false
|
208
|
-
requirements:
|
209
|
-
- - ! '>='
|
210
|
-
- !ruby/object:Gem::Version
|
211
|
-
version: 0.10.5
|
212
111
|
- !ruby/object:Gem::Dependency
|
213
112
|
name: rake
|
214
113
|
requirement: !ruby/object:Gem::Requirement
|
215
|
-
none: false
|
216
114
|
requirements:
|
217
115
|
- - ! '>='
|
218
116
|
- !ruby/object:Gem::Version
|
@@ -220,7 +118,6 @@ dependencies:
|
|
220
118
|
type: :development
|
221
119
|
prerelease: false
|
222
120
|
version_requirements: !ruby/object:Gem::Requirement
|
223
|
-
none: false
|
224
121
|
requirements:
|
225
122
|
- - ! '>='
|
226
123
|
- !ruby/object:Gem::Version
|
@@ -228,19 +125,17 @@ dependencies:
|
|
228
125
|
- !ruby/object:Gem::Dependency
|
229
126
|
name: rspec
|
230
127
|
requirement: !ruby/object:Gem::Requirement
|
231
|
-
none: false
|
232
128
|
requirements:
|
233
129
|
- - ! '>='
|
234
130
|
- !ruby/object:Gem::Version
|
235
|
-
version:
|
131
|
+
version: '0'
|
236
132
|
type: :development
|
237
133
|
prerelease: false
|
238
134
|
version_requirements: !ruby/object:Gem::Requirement
|
239
|
-
none: false
|
240
135
|
requirements:
|
241
136
|
- - ! '>='
|
242
137
|
- !ruby/object:Gem::Version
|
243
|
-
version:
|
138
|
+
version: '0'
|
244
139
|
description: Gem to ease the pain of managing capybara driver config and provide a
|
245
140
|
home for common utils and patches
|
246
141
|
email:
|
@@ -260,19 +155,12 @@ files:
|
|
260
155
|
- README.rdoc
|
261
156
|
- Rakefile
|
262
157
|
- frameworks-capybara.gemspec
|
158
|
+
- lib/extensions/capybara-mechanize-extensions.rb
|
263
159
|
- lib/frameworks-capybara.rb
|
264
160
|
- lib/frameworks/capybara.rb
|
265
161
|
- lib/frameworks/cucumber.rb
|
266
|
-
- lib/monkey-patches/capybara-mechanize-patches.rb
|
267
|
-
- lib/monkey-patches/capybara-patches.rb
|
268
|
-
- lib/monkey-patches/cucumber-patches.rb
|
269
|
-
- lib/monkey-patches/mechanize-patches.rb
|
270
|
-
- lib/monkey-patches/net-http-persistent-patches.rb
|
271
|
-
- lib/monkey-patches/send-keys.rb
|
272
|
-
- lib/monkey-patches/webdriver-patches.rb
|
273
162
|
- lib/tasks/frameworks-tasks.rb
|
274
163
|
- lib/version.rb
|
275
|
-
- spec/capybara_mechanize_patches_spec.rb
|
276
164
|
- spec/frameworks_capybara_spec.rb
|
277
165
|
- spec/frameworks_cucumber_spec.rb
|
278
166
|
- spec/mock.default/prefs.js
|
@@ -281,33 +169,26 @@ files:
|
|
281
169
|
- spec/unit_test_monkeypatches.rb
|
282
170
|
homepage:
|
283
171
|
licenses: []
|
172
|
+
metadata: {}
|
284
173
|
post_install_message:
|
285
174
|
rdoc_options: []
|
286
175
|
require_paths:
|
287
176
|
- lib
|
288
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
289
|
-
none: false
|
290
178
|
requirements:
|
291
179
|
- - ! '>='
|
292
180
|
- !ruby/object:Gem::Version
|
293
181
|
version: '0'
|
294
|
-
segments:
|
295
|
-
- 0
|
296
|
-
hash: -2675319668595312494
|
297
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
|
-
none: false
|
299
183
|
requirements:
|
300
184
|
- - ! '>='
|
301
185
|
- !ruby/object:Gem::Version
|
302
186
|
version: '0'
|
303
|
-
segments:
|
304
|
-
- 0
|
305
|
-
hash: -2675319668595312494
|
306
187
|
requirements: []
|
307
188
|
rubyforge_project:
|
308
|
-
rubygems_version:
|
189
|
+
rubygems_version: 2.4.2
|
309
190
|
signing_key:
|
310
|
-
specification_version:
|
191
|
+
specification_version: 4
|
311
192
|
summary: Gem to ease the pain of managing capybara driver config and provide a home
|
312
193
|
for common utils and patches
|
313
194
|
test_files: []
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'selenium-webdriver'
|
2
|
-
require 'capybara/cucumber'
|
3
|
-
|
4
|
-
|
5
|
-
##
|
6
|
-
#Monkey Patch's - Use with care!
|
7
|
-
#
|
8
|
-
class Capybara::Selenium::Node
|
9
|
-
def style(prop)
|
10
|
-
native.style(prop)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Capybara::Node::Element
|
15
|
-
def style(prop)
|
16
|
-
base.style(prop)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Capybara::Driver::Node
|
21
|
-
def style(prop)
|
22
|
-
raise NotImplementedError
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Capybara::Selenium::Driver
|
27
|
-
def cookies
|
28
|
-
browser.manage.all_cookies
|
29
|
-
end
|
30
|
-
|
31
|
-
def cookie_named(name)
|
32
|
-
browser.manage.cookie_named(name)
|
33
|
-
end
|
34
|
-
|
35
|
-
def delete_cookie(cookie)
|
36
|
-
browser.manage.delete_cookie(cookie)
|
37
|
-
end
|
38
|
-
|
39
|
-
def delete_all_cookies
|
40
|
-
browser.manage.delete_all_cookies
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_cookie(attribs)
|
44
|
-
browser.manage.add_cookie(attribs)
|
45
|
-
end
|
46
|
-
|
47
|
-
def delete_cookies_in_domain(domain)
|
48
|
-
browser.manage.delete_cookies_in_domain(domain)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module Capybara
|
53
|
-
class Session
|
54
|
-
##
|
55
|
-
# Get all cookies
|
56
|
-
#
|
57
|
-
# @return [Array<Hash>] list of cookies
|
58
|
-
#
|
59
|
-
def cookies
|
60
|
-
driver.cookies
|
61
|
-
end
|
62
|
-
|
63
|
-
##
|
64
|
-
# Get the cookie with the given name
|
65
|
-
#
|
66
|
-
# @param [String] name the name of the cookie
|
67
|
-
# @return [Hash, nil] the cookie, or nil if it wasn't found.
|
68
|
-
#
|
69
|
-
def cookie_named(name)
|
70
|
-
driver.cookie_named(name)
|
71
|
-
end
|
72
|
-
|
73
|
-
def delete_cookie(cookie)
|
74
|
-
driver.delete_cookie(cookie)
|
75
|
-
end
|
76
|
-
|
77
|
-
def delete_all_cookies
|
78
|
-
driver.delete_all_cookies
|
79
|
-
end
|
80
|
-
|
81
|
-
def add_cookie(attribs)
|
82
|
-
driver.add_cookie(attribs)
|
83
|
-
end
|
84
|
-
|
85
|
-
def delete_cookies_in_domain(domain)
|
86
|
-
driver.delete_cookies_in_domain(domain)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'cucumber/formatter/html.rb'
|
2
|
-
module Cucumber
|
3
|
-
module Formatter
|
4
|
-
class Html
|
5
|
-
TEAM_NAME = 'BBC Frameworks'
|
6
|
-
def before_features(features)
|
7
|
-
@project_name = ENV['PROJECT_NAME'] || ''
|
8
|
-
unless @project_name.empty? then @project_name += ' - ' end
|
9
|
-
|
10
|
-
if Cucumber::Ast::Feature.method_defined?(:step_count)
|
11
|
-
@step_count = features.step_count # cucumber >=1.3.0
|
12
|
-
else
|
13
|
-
@step_count = get_step_count(features) # cucumber <1.3.0
|
14
|
-
end
|
15
|
-
|
16
|
-
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
17
|
-
@builder.declare!(
|
18
|
-
:DOCTYPE,
|
19
|
-
:html,
|
20
|
-
:PUBLIC,
|
21
|
-
'-//W3C//DTD XHTML 1.0 Strict//EN',
|
22
|
-
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
23
|
-
)
|
24
|
-
|
25
|
-
@builder << '<html xmlns ="http://www.w3.org/1999/xhtml">'
|
26
|
-
@builder.head do
|
27
|
-
@builder.meta(:content => 'text/html;charset=utf-8')
|
28
|
-
@builder.title 'Cucumber'
|
29
|
-
inline_css
|
30
|
-
inline_js
|
31
|
-
end
|
32
|
-
@builder << '<body>'
|
33
|
-
@builder << "<!-- Step count #{@step_count}-->"
|
34
|
-
@builder << '<div class="cucumber">'
|
35
|
-
@builder.div(:id => 'cucumber-header') do
|
36
|
-
@builder.div(:id => 'label') do
|
37
|
-
@builder.h1("#{@project_name}#{TEAM_NAME} - #{Time.now.strftime('%d/%m/%y-%H:%M:%S')}")
|
38
|
-
end
|
39
|
-
@builder.div(:id => 'summary') do
|
40
|
-
@builder.p('',:id => 'totals')
|
41
|
-
@builder.p('',:id => 'duration')
|
42
|
-
@builder.div(:id => 'expand-collapse') do
|
43
|
-
@builder.p('Expand All', :id => 'expander')
|
44
|
-
@builder.p('Collapse All', :id => 'collapser')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require 'mechanize'
|
2
|
-
#This patch is required Mechanize runs the clear before each new request
|
3
|
-
#and not after each response, operationaly this is fine, but because
|
4
|
-
#we check after response and it may be the last response we need it to clear here.
|
5
|
-
class Mechanize::CookieJar
|
6
|
-
alias_method :old_add, :add
|
7
|
-
def add(*args)
|
8
|
-
cleanup
|
9
|
-
old_add(*args)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
#This patch may still be required, think it is only not needed now because we don't run
|
13
|
-
#full facebook journey, only mock in idtests
|
14
|
-
=begin
|
15
|
-
# Fetches the URL passed in and returns a page.
|
16
|
-
def get(uri, parameters = [], referer = nil, headers = {})
|
17
|
-
method = :get
|
18
|
-
|
19
|
-
if Hash === uri then
|
20
|
-
options = uri
|
21
|
-
location = Gem.location_of_caller.join ':'
|
22
|
-
warn "#{location}: Mechanize#get with options hash is deprecated and will be removed October 2011"
|
23
|
-
|
24
|
-
raise ArgumentError, "url must be specified" unless uri = options[:url]
|
25
|
-
parameters = options[:params] || []
|
26
|
-
referer = options[:referer]
|
27
|
-
headers = options[:headers]
|
28
|
-
method = options[:verb] || method
|
29
|
-
end
|
30
|
-
|
31
|
-
#FRAMEWORKS-PATCH - CHANGE LOGIC in 'if' so that =~ becomes !~ in order for
|
32
|
-
#referer to be set correctly.
|
33
|
-
referer ||=
|
34
|
-
if uri.to_s !~ %r{\Ahttps?://}
|
35
|
-
Page.new(nil, {'content-type'=>'text/html'})
|
36
|
-
else
|
37
|
-
current_page || Page.new(nil, {'content-type'=>'text/html'})
|
38
|
-
end
|
39
|
-
|
40
|
-
# FIXME: Huge hack so that using a URI as a referer works. I need to
|
41
|
-
# refactor everything to pass around URIs but still support
|
42
|
-
# Mechanize::Page#base
|
43
|
-
unless referer.is_a?(Mechanize::File)
|
44
|
-
referer = referer.is_a?(String) ?
|
45
|
-
Page.new(URI.parse(referer), {'content-type' => 'text/html'}) :
|
46
|
-
Page.new(referer, {'content-type' => 'text/html'})
|
47
|
-
end
|
48
|
-
|
49
|
-
# fetch the page
|
50
|
-
headers ||= {}
|
51
|
-
page = @agent.fetch uri, method, headers, parameters, referer
|
52
|
-
add_to_history(page)
|
53
|
-
yield page if block_given?
|
54
|
-
page
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
=end
|
59
|
-
|
60
|
-
# This patch prevents Mechanize from raising a Mechanize::ResponseCodeError
|
61
|
-
# when the HTTP Response Code is in `allowed_error_codes`.
|
62
|
-
# https://github.com/tenderlove/mechanize/pull/248
|
63
|
-
class Mechanize::HTTP::Agent
|
64
|
-
attr_accessor :allowed_error_codes
|
65
|
-
|
66
|
-
alias_method :old_initialize, :initialize
|
67
|
-
def initialize
|
68
|
-
@allowed_error_codes = []
|
69
|
-
old_initialize
|
70
|
-
end
|
71
|
-
|
72
|
-
def fetch uri, method = :get, headers = {}, params = [],
|
73
|
-
referer = current_page, redirects = 0
|
74
|
-
referer_uri = referer ? referer.uri : nil
|
75
|
-
|
76
|
-
uri = resolve uri, referer
|
77
|
-
|
78
|
-
uri, params = resolve_parameters uri, method, params
|
79
|
-
|
80
|
-
request = http_request uri, method, params
|
81
|
-
|
82
|
-
connection = connection_for uri
|
83
|
-
|
84
|
-
request_auth request, uri
|
85
|
-
|
86
|
-
disable_keep_alive request
|
87
|
-
enable_gzip request
|
88
|
-
|
89
|
-
request_language_charset request
|
90
|
-
request_cookies request, uri
|
91
|
-
request_host request, uri
|
92
|
-
request_referer request, uri, referer_uri
|
93
|
-
request_user_agent request
|
94
|
-
request_add_headers request, headers
|
95
|
-
|
96
|
-
pre_connect request
|
97
|
-
|
98
|
-
# Consult robots.txt
|
99
|
-
if robots && uri.is_a?(URI::HTTP)
|
100
|
-
robots_allowed?(uri) or raise Mechanize::RobotsDisallowedError.new(uri)
|
101
|
-
end
|
102
|
-
|
103
|
-
# Add If-Modified-Since if page is in history
|
104
|
-
page = visited_page(uri)
|
105
|
-
|
106
|
-
if (page = visited_page(uri)) and page.response['Last-Modified']
|
107
|
-
request['If-Modified-Since'] = page.response['Last-Modified']
|
108
|
-
end if(@conditional_requests)
|
109
|
-
|
110
|
-
# Specify timeouts if given
|
111
|
-
connection.open_timeout = @open_timeout if @open_timeout
|
112
|
-
connection.read_timeout = @read_timeout if @read_timeout
|
113
|
-
|
114
|
-
request_log request
|
115
|
-
|
116
|
-
response_body_io = nil
|
117
|
-
|
118
|
-
# Send the request
|
119
|
-
begin
|
120
|
-
response = connection.request(uri, request) { |res|
|
121
|
-
response_log res
|
122
|
-
|
123
|
-
response_body_io = response_read res, request, uri
|
124
|
-
|
125
|
-
res
|
126
|
-
}
|
127
|
-
rescue Mechanize::ChunkedTerminationError => e
|
128
|
-
raise unless @ignore_bad_chunking
|
129
|
-
|
130
|
-
response = e.response
|
131
|
-
response_body_io = e.body_io
|
132
|
-
end
|
133
|
-
|
134
|
-
hook_content_encoding response, uri, response_body_io
|
135
|
-
|
136
|
-
response_body_io = response_content_encoding response, response_body_io if
|
137
|
-
request.response_body_permitted?
|
138
|
-
|
139
|
-
post_connect uri, response, response_body_io
|
140
|
-
|
141
|
-
page = response_parse response, response_body_io, uri
|
142
|
-
|
143
|
-
response_cookies response, uri, page
|
144
|
-
|
145
|
-
meta = response_follow_meta_refresh response, uri, page, redirects
|
146
|
-
|
147
|
-
return meta if meta
|
148
|
-
|
149
|
-
case response
|
150
|
-
when Net::HTTPSuccess
|
151
|
-
if robots && page.is_a?(Mechanize::Page)
|
152
|
-
page.parser.noindex? and raise Mechanize::RobotsDisallowedError.new(uri)
|
153
|
-
end
|
154
|
-
|
155
|
-
page
|
156
|
-
when Mechanize::FileResponse
|
157
|
-
page
|
158
|
-
when Net::HTTPNotModified
|
159
|
-
log.debug("Got cached page") if log
|
160
|
-
visited_page(uri) || page
|
161
|
-
when Net::HTTPRedirection
|
162
|
-
response_redirect response, method, page, redirects, headers, referer
|
163
|
-
when Net::HTTPUnauthorized
|
164
|
-
response_authenticate(response, page, uri, request, headers, params,
|
165
|
-
referer)
|
166
|
-
else
|
167
|
-
# BEGIN PATCH
|
168
|
-
if @allowed_error_codes.any? {|code| code.to_s == page.code} then
|
169
|
-
if robots && page.is_a?(Mechanize::Page)
|
170
|
-
page.parser.noindex? and raise Mechanize::RobotsDisallowedError.new(uri)
|
171
|
-
end
|
172
|
-
|
173
|
-
page
|
174
|
-
else
|
175
|
-
raise Mechanize::ResponseCodeError.new(page, 'unhandled response')
|
176
|
-
end
|
177
|
-
# END PATCH
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
#Adding no_proxy_host logic for Mechanize2 which uses this
|
2
|
-
#gem for it's HTTP client logic
|
3
|
-
#TODO: Grab from envirnment variable optionally, or provide list
|
4
|
-
class Net::HTTP::Persistent
|
5
|
-
|
6
|
-
##
|
7
|
-
# Creates a new connection for +uri+
|
8
|
-
def connection_for uri
|
9
|
-
Thread.current[@generation_key] ||= Hash.new { |h,k| h[k] = {} }
|
10
|
-
Thread.current[@ssl_generation_key] ||= Hash.new { |h,k| h[k] = {} }
|
11
|
-
Thread.current[@request_key] ||= Hash.new 0
|
12
|
-
Thread.current[@timeout_key] ||= Hash.new EPOCH
|
13
|
-
|
14
|
-
use_ssl = uri.scheme.downcase == 'https'
|
15
|
-
|
16
|
-
if use_ssl then
|
17
|
-
ssl_generation = @ssl_generation
|
18
|
-
|
19
|
-
ssl_cleanup ssl_generation
|
20
|
-
|
21
|
-
connections = Thread.current[@ssl_generation_key][ssl_generation]
|
22
|
-
else
|
23
|
-
generation = @generation
|
24
|
-
|
25
|
-
cleanup generation
|
26
|
-
|
27
|
-
connections = Thread.current[@generation_key][generation]
|
28
|
-
end
|
29
|
-
|
30
|
-
net_http_args = [uri.host, uri.port]
|
31
|
-
connection_id = net_http_args.join ':'
|
32
|
-
#
|
33
|
-
#Frameworks patch (and condition)
|
34
|
-
if @proxy_uri and !uri.host.include? 'sandbox' then
|
35
|
-
connection_id << @proxy_connection_id
|
36
|
-
net_http_args.concat @proxy_args
|
37
|
-
end
|
38
|
-
|
39
|
-
connection = connections[connection_id]
|
40
|
-
|
41
|
-
unless connection = connections[connection_id] then
|
42
|
-
connections[connection_id] = http_class.new(*net_http_args)
|
43
|
-
connection = connections[connection_id]
|
44
|
-
ssl connection if use_ssl
|
45
|
-
else
|
46
|
-
reset connection if expired? connection
|
47
|
-
end
|
48
|
-
|
49
|
-
unless connection.started? then
|
50
|
-
connection.set_debug_output @debug_output if @debug_output
|
51
|
-
connection.open_timeout = @open_timeout if @open_timeout
|
52
|
-
connection.read_timeout = @read_timeout if @read_timeout
|
53
|
-
|
54
|
-
connection.start
|
55
|
-
|
56
|
-
socket = connection.instance_variable_get :@socket
|
57
|
-
|
58
|
-
if socket then # for fakeweb
|
59
|
-
@socket_options.each do |option|
|
60
|
-
socket.io.setsockopt(*option)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
connection
|
66
|
-
rescue Errno::ECONNREFUSED
|
67
|
-
raise Error, "connection refused: #{connection.address}:#{connection.port}"
|
68
|
-
rescue Errno::EHOSTDOWN
|
69
|
-
raise Error, "host down: #{connection.address}:#{connection.port}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|