Class: Mamemose::Server

Inherits:
Object
  • Object
show all
Includes:
HTML, Path
Defined in:
lib/mamemose.rb

Instance Method Summary collapse

Methods included from HTML

#footer_html, #header_html, #link_list, #search_form

Methods included from Path

#docpath, #escape, #escaped_basename, #fullpath, #showpath, #uri

Constructor Details

#initialize(port) ⇒ Server

Returns a new instance of Server.



41
42
43
44
45
# File 'lib/mamemose.rb', line 41

def initialize(port)
  @mamemose = WEBrick::HTTPServer.new({ :Port => port ? port.to_i : PORT })
  trap(:INT){finalize}
  trap(:TERM){finalize}
end

Instance Method Details

#file(filename) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/mamemose.rb', line 71

def file(filename)
  @mamemose.mount_proc('/') do |req, res|
    res['Cache-Control'] = 'no-cache, no-store, must-revalidate'
    res['Pragma'] = 'no-cache'
    res['Expires'] = '0'
    res = req_file(File.absolute_path(filename), res, true)
    res.content_type = CONTENT_TYPE
  end
  start
end

#serverObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mamemose.rb', line 51

def server
  @mamemose.mount_proc('/') do |req, res|
    res['Cache-Control'] = 'no-cache, no-store, must-revalidate'
    res['Pragma'] = 'no-cache'
    res['Expires'] = '0'

    p fullpath(req.path)
    if req.path =~ /^\/search/
      res = req_search(req, res)
    elsif File.directory?(fullpath(req.path))
      res = req_index(req, res)
    elsif File.exists?(fullpath(req.path))
      res = req_file(fullpath(req.path), res, false)
    else
      res.status = WEBrick::HTTPStatus::RC_NOT_FOUND
    end
  end
  start
end

#startObject



47
48
49
# File 'lib/mamemose.rb', line 47

def start
  @mamemose.start
end