browsermob-proxy 0.1.8.rc1 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/browsermob-proxy.gemspec +1 -1
- data/lib/browsermob/proxy/server.rb +57 -13
- data/lib/browsermob/proxy/version.rb +1 -1
- data/spec/e2e/selenium_spec.rb +6 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7c5eb8a3141707dbe6e94473f0332074603abf0
|
4
|
+
data.tar.gz: fa973c10a15c6ba4eb50314387244b1e0f83535a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe0a416c7a286bfba23f0ede933f37b13b6c279af029496015fb03f9bec85290a89f88773f0f890849619d31d437932923de9ff333cc96c685c8c44039f92ccd
|
7
|
+
data.tar.gz: 744b35697c60c51e821f834c7c32717cd60acdcc367a21c186bc9b3fb4b11ea11aa4cd899259930bd5eecc9fd598b7eca2fe59baae0090db0834e264f58e87cd
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Manually:
|
|
15
15
|
require 'selenium/webdriver'
|
16
16
|
require 'browsermob/proxy'
|
17
17
|
|
18
|
-
server = BrowserMob::Proxy::Server.new("/path/to/
|
18
|
+
server = BrowserMob::Proxy::Server.new("/path/to/downloads/browsermob-proxy/bin/browsermob-proxy") #=> #<BrowserMob::Proxy::Server:0x000001022c6ea8 ...>
|
19
19
|
server.start
|
20
20
|
|
21
21
|
proxy = server.create_proxy #=> #<BrowserMob::Proxy::Client:0x0000010224bdc0 ...>
|
data/browsermob-proxy.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rubyforge_project = "browsermob-proxy-rb"
|
17
17
|
|
18
18
|
s.add_runtime_dependency "rest-client"
|
19
|
-
s.add_runtime_dependency "childprocess"
|
19
|
+
s.add_runtime_dependency "childprocess", "~> 0.5"
|
20
20
|
s.add_runtime_dependency "multi_json", "~> 1.0"
|
21
21
|
s.add_runtime_dependency "har"
|
22
22
|
|
@@ -7,25 +7,31 @@ module BrowserMob
|
|
7
7
|
class Server
|
8
8
|
attr_reader :port
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
#
|
11
|
+
# Create a new server instance
|
12
|
+
#
|
13
|
+
# @param [String] path Path to the BrowserMob Proxy server executable
|
14
|
+
# @param [Hash] opts options to create the server with
|
15
|
+
# @option opts [Integer] port What port to start the server on
|
16
|
+
# @option opts [Boolean] log Show server output (server inherits stdout/stderr)
|
17
|
+
# @option opts [Integer] timeout Seconds to wait for server to launch before timing out.
|
18
|
+
#
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
20
|
+
def initialize(path, opts = {})
|
21
|
+
assert_executable path
|
18
22
|
|
19
|
-
@path
|
20
|
-
@port
|
23
|
+
@path = path
|
24
|
+
@port = Integer(opts[:port] || 8080)
|
25
|
+
@timeout = Integer(opts[:timeout] || 10)
|
26
|
+
@log = !!opts[:log]
|
21
27
|
|
22
|
-
@process =
|
23
|
-
@process.io.inherit! if opts[:log]
|
28
|
+
@process = create_process
|
24
29
|
end
|
25
30
|
|
26
31
|
def start
|
27
32
|
@process.start
|
28
|
-
|
33
|
+
|
34
|
+
wait_for_startup
|
29
35
|
|
30
36
|
pid = Process.pid
|
31
37
|
at_exit { stop if Process.pid == pid }
|
@@ -47,6 +53,28 @@ module BrowserMob
|
|
47
53
|
|
48
54
|
private
|
49
55
|
|
56
|
+
def create_process
|
57
|
+
process = ChildProcess.new(@path, "--port", @port.to_s)
|
58
|
+
process.leader = true
|
59
|
+
|
60
|
+
process.io.inherit! if @log
|
61
|
+
|
62
|
+
process
|
63
|
+
end
|
64
|
+
|
65
|
+
def wait_for_startup
|
66
|
+
end_time = Time.now + @timeout
|
67
|
+
|
68
|
+
sleep 0.1 until (listening? && initialized?) || Time.now > end_time || !@process.alive?
|
69
|
+
|
70
|
+
if Time.now > end_time
|
71
|
+
raise TimeoutError, "timed out waiting for the server to start (rerun with :log => true to see process output)"
|
72
|
+
end
|
73
|
+
|
74
|
+
unless @process.alive?
|
75
|
+
raise ServerDiedError, "unable to launch the server (rerun with :log => true to see process output)"
|
76
|
+
end
|
77
|
+
end
|
50
78
|
|
51
79
|
def listening?
|
52
80
|
TCPSocket.new("127.0.0.1", port).close
|
@@ -61,7 +89,23 @@ module BrowserMob
|
|
61
89
|
rescue RestClient::Exception
|
62
90
|
false
|
63
91
|
end
|
64
|
-
end # Server
|
65
92
|
|
93
|
+
def assert_executable(path)
|
94
|
+
unless File.exist?(path)
|
95
|
+
raise Errno::ENOENT, path
|
96
|
+
end
|
97
|
+
|
98
|
+
unless File.executable?(path)
|
99
|
+
raise Errno::EACCES, "not executable: #{path}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class TimeoutError < StandardError
|
104
|
+
end
|
105
|
+
|
106
|
+
class ServerDiedError < StandardError
|
107
|
+
end
|
108
|
+
|
109
|
+
end # Server
|
66
110
|
end # Proxy
|
67
111
|
end # BrowserMob
|
data/spec/e2e/selenium_spec.rb
CHANGED
@@ -105,7 +105,9 @@ describe "Proxy + WebDriver" do
|
|
105
105
|
proxy.blacklist(Regexp.quote(dest), 404)
|
106
106
|
driver.get dest
|
107
107
|
|
108
|
-
proxy.har.entries.
|
108
|
+
entry = proxy.har.entries.find { |e| e.request.url == dest }
|
109
|
+
entry.should_not be_nil
|
110
|
+
entry.response.status.should == 404
|
109
111
|
end
|
110
112
|
|
111
113
|
it "allows access to urls outside blacklist" do
|
@@ -124,7 +126,9 @@ describe "Proxy + WebDriver" do
|
|
124
126
|
proxy.clear_blacklist
|
125
127
|
driver.get dest
|
126
128
|
|
127
|
-
proxy.har.entries.
|
129
|
+
entry = proxy.har.entries.find { |e| e.request.url == dest }
|
130
|
+
entry.should_not be_nil
|
131
|
+
entry.response.status.should_not == 404
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browsermob-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.8
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jari.bakken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: childprocess
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.5'
|
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
|
-
version: '0'
|
40
|
+
version: '0.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: multi_json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,9 +181,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
|
-
- - "
|
184
|
+
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version:
|
186
|
+
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project: browsermob-proxy-rb
|
189
189
|
rubygems_version: 2.2.0
|