class Bridgetown::Commands::Serve::Servlet
Constants
- DEFAULTS
Public Class Methods
new(server, root, callbacks)
click to toggle source
Calls superclass method
# File lib/bridgetown-core/commands/serve/servlet.rb, line 14 def initialize(server, root, callbacks) # So we can access them easily. @bridgetown_opts = server.config[:BridgetownOptions] set_defaults super end
Public Instance Methods
do_GET(req, res)
click to toggle source
rubocop:disable Naming/MethodName
Calls superclass method
# File lib/bridgetown-core/commands/serve/servlet.rb, line 39 def do_GET(req, res) rtn = super validate_and_ensure_charset(req, res) res.header.merge!(@headers) rtn end
search_file(req, res, basename)
click to toggle source
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.
Calls superclass method
# File lib/bridgetown-core/commands/serve/servlet.rb, line 31 def search_file(req, res, basename) # /file.* > /file/index.html > /file.html super || super(req, res, "#{basename}.html") || super(req, res, "#{basename}.xhtml") end
search_index_file(req, res)
click to toggle source
Calls superclass method
# File lib/bridgetown-core/commands/serve/servlet.rb, line 21 def search_index_file(req, res) super || search_file(req, res, ".html") || search_file(req, res, ".xhtml") end
Private Instance Methods
set_defaults()
click to toggle source
# File lib/bridgetown-core/commands/serve/servlet.rb, line 59 def set_defaults hash_ = @bridgetown_opts.fetch("webrick", {}).fetch("headers", {}) DEFAULTS.each_with_object(@headers = hash_) do |(key, val), hash| hash[key] = val unless hash.key?(key) end end
validate_and_ensure_charset(_req, res)
click to toggle source
rubocop:enable Naming/MethodName
# File lib/bridgetown-core/commands/serve/servlet.rb, line 50 def validate_and_ensure_charset(_req, res) key = res.header.keys.grep(%r!content-type!i).first typ = res.header[key] unless %r!;\s*charset=!.match?(typ) res.header[key] = "#{typ}; charset=#{@bridgetown_opts["encoding"]}" end end