Class: FakeSMTPd::HTTPServer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HTTPServer

Returns a new instance of HTTPServer.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fakesmtpd/server.rb', line 40

def initialize(options = {})
  @port = options.fetch(:port)
  @smtpd = options.fetch(:smtpd)
  super(
    @port,
    options[:host] || '0.0.0.0',
    options[:max_connections] || 4,
    options[:logfile],
    options[:audit] || !!ENV['FAKESMTPD_AUDIT'] || false,
    options[:debug] || !!ENV['FAKESMTPD_DEBUG'] || false
  )
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



38
39
40
# File 'lib/fakesmtpd/server.rb', line 38

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



38
39
40
# File 'lib/fakesmtpd/server.rb', line 38

def server
  @server
end

#smtpdObject (readonly)

Returns the value of attribute smtpd.



38
39
40
# File 'lib/fakesmtpd/server.rb', line 38

def smtpd
  @smtpd
end

Instance Method Details

#serve(io) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/fakesmtpd/server.rb', line 64

def serve(io)
  io.set_encoding('UTF-8')
  request_line = io.gets
  path = request_line.split[1]
  handle_client(request_line, path, io)
rescue => e
  handle_500(path, io, e)
end

#start(*args) ⇒ Object



53
54
55
56
57
# File 'lib/fakesmtpd/server.rb', line 53

def start(*args)
  super(*args)
  log "FakeSMTPd HTTP server serving on #{port}"
  log "PID=#{$$} Thread=#{Thread.current.inspect}"
end

#stop(*args) ⇒ Object



59
60
61
62
# File 'lib/fakesmtpd/server.rb', line 59

def stop(*args)
  log "FakeSMTPd HTTP server stopping"
  super(*args)
end