Class: BetterCap::Network::Servers::HTTPD

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/network/servers/httpd.rb

Overview

Simple HTTP server class used to serve static assets when needed.

Instance Method Summary collapse

Constructor Details

#initialize(port = 8081, path = './') ⇒ HTTPD

Initialize the HTTP server with the specified tcp port using path as the document root.



22
23
24
25
26
27
28
29
30
31
# File 'lib/bettercap/network/servers/httpd.rb', line 22

def initialize( port = 8081, path = './' )
  @port = port
  @path = path
  @server = WEBrick::HTTPServer.new(
    Port: @port,
    DocumentRoot: @path,
    Logger: WEBrick::Log.new("/dev/null"),
    AccessLog: []
  )
end

Instance Method Details

#startObject

Start the server.



34
35
36
37
38
39
# File 'lib/bettercap/network/servers/httpd.rb', line 34

def start
  Logger.info "[#{'HTTPD'.green}] Starting on port #{@port} and path #{@path} ..."
  @thread = Thread.new {
    @server.start
  }
end

#stopObject

Stop the server.



42
43
44
45
46
47
# File 'lib/bettercap/network/servers/httpd.rb', line 42

def stop
  Logger.info 'Stopping HTTPD ...'

  @server.stop
  @thread.join
end