Class: BrowserMob::Proxy::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/browsermob/proxy/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, opts = {}) ⇒ Server

Returns a new instance of Server.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/browsermob/proxy/server.rb', line 10

def initialize(path, opts = {})
  unless File.exist?(path)
    raise Errno::ENOENT, path
  end

  unless File.executable?(path)
    raise Errno::EACCES, "not executable: #{path}"
  end

  @path = path
  @port = Integer(opts[:port] || 8080)

  @process = ChildProcess.new(path, "--port", port.to_s)
  @process.io.inherit! if opts[:log]
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/browsermob/proxy/server.rb', line 8

def port
  @port
end

Instance Method Details

#create_proxyObject



40
41
42
# File 'lib/browsermob/proxy/server.rb', line 40

def create_proxy
  Client.from url
end

#startObject



26
27
28
29
30
31
32
33
34
# File 'lib/browsermob/proxy/server.rb', line 26

def start
  @process.start
  sleep 0.1 until listening?

  pid = Process.pid
  at_exit { stop if Process.pid == pid }

  self
end

#stopObject



44
45
46
# File 'lib/browsermob/proxy/server.rb', line 44

def stop
  @process.stop if @process.alive?
end

#urlObject



36
37
38
# File 'lib/browsermob/proxy/server.rb', line 36

def url
  "http://localhost:#{port}"
end