Class: Jekyll::Commands::Serve::Servlet

Inherits:
WEBrick::HTTPServlet::FileHandler
  • Object
show all
Defined in:
lib/jekyll/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.


134
135
136
137
138
139
# File 'lib/jekyll/commands/serve/servlet.rb', line 134

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

Instance Method Details

#do_GET(req, res) ⇒ Object

rubocop:disable Naming/MethodName


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/jekyll/commands/serve/servlet.rb', line 159

def do_GET(req, res)
  rtn = super

  if @jekyll_opts["livereload"]
    return rtn if SkipAnalyzer.skip_processing?(req, res, @jekyll_opts)

    processor = BodyProcessor.new(res.body, @jekyll_opts)
    processor.process!
    res.body = processor.new_body
    res.content_length = processor.content_length.to_s

    if processor.livereload_added
      # Add a header to indicate that the page content has been modified
      res["X-Rack-LiveReload"] = "1"
    end
  end

  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.


151
152
153
154
155
156
# File 'lib/jekyll/commands/serve/servlet.rb', line 151

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) ⇒ Object


141
142
143
144
145
# File 'lib/jekyll/commands/serve/servlet.rb', line 141

def search_index_file(req, res)
  super ||
    search_file(req, res, ".html") ||
    search_file(req, res, ".xhtml")
end