Class: Proxie::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = 8080, args = {}) ⇒ Server

Initialize server instance Options:

:default  => true   Skip static filess like images, stylesheets, swf, etc
:html     => true   Skip if html in body
:js       => true   Skip javascripts


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

def initialize(port=8080, args={})
  @options = {
    :default => args[:default]  || true,
    :js      => args[:js]       || true,
    :images  => args[:images]   || true
  }
  
  @server = WEBrick::HTTPProxyServer.new(
    :Port => port,
    :AccessLog => [],
    :ProxyContentHandler => Proc.new { |req, resp| process(req, resp) }
  )
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/proxie/server.rb', line 5

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/proxie/server.rb', line 4

def options
  @options
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/proxie/server.rb', line 3

def port
  @port
end

Instance Method Details

#startObject

Start proxy server

Raises:

  • (RuntimeError)


34
35
36
37
# File 'lib/proxie/server.rb', line 34

def start
  raise RuntimeError, 'Logger is not defined!' if @logger.nil?
  @server.start
end

#stopObject

Stop proxy server



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

def stop
  @server.shutdown
end