Class: Bunto::Commands::Serve::Servlet

Inherits:
WEBrick::HTTPServlet::FileHandler
  • Object
show all
Defined in:
lib/bunto/commands/serve/servlet.rb

Constant Summary collapse

DEFAULTS =
{
  "Cache-Control" => "private, max-age=0, proxy-revalidate, " \
    "no-store, no-cache, must-revalidate",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(server, root, callbacks) ⇒ Servlet

Returns a new instance of Servlet.



12
13
14
15
16
17
# File 'lib/bunto/commands/serve/servlet.rb', line 12

def initialize(server, root, callbacks)
  # So we can access them easily.
  @bunto_opts = server.config[:BuntoOptions]
  set_defaults
  super
end

Instance Method Details

#do_GET(req, res) ⇒ Object

rubocop:disable Style/MethodName



29
30
31
32
33
34
# File 'lib/bunto/commands/serve/servlet.rb', line 29

def do_GET(req, res)
  rtn = super
  validate_and_ensure_charset(req, res)
  res.header.merge!(@headers)
  rtn
end

#search_file(req, res, basename) ⇒ Object

Add the ability to tap file.html the same way that Nginx does on our Docker images (or on GitHub Pages.) The difference is that we might end up with a different preference on which comes first.



23
24
25
26
# File 'lib/bunto/commands/serve/servlet.rb', line 23

def search_file(req, res, basename)
  # /file.* > /file/index.html > /file.html
  super || super(req, res, "#{basename}.html")
end