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.



27
28
29
30
31
# File 'lib/mamemose.rb', line 27

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



57
58
59
60
61
62
63
64
65
66
# File 'lib/mamemose.rb', line 57

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mamemose.rb', line 37

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



33
34
35
# File 'lib/mamemose.rb', line 33

def start
  @mamemose.start
end