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
140
# 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]
  @mime_types_charset = server.config[:MimeTypesCharset]
  set_defaults
  super
end

Instance Method Details

#do_GET(req, res) ⇒ Object

rubocop:disable Naming/MethodName



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

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

  conditionally_inject_charset(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.



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

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



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

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