Class: SiteDiff::Webserver::ResultServer::CacheServlet
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- SiteDiff::Webserver::ResultServer::CacheServlet
- Defined in:
- lib/sitediff/webserver/resultserver.rb
Overview
Display a page from the cache
Instance Method Summary collapse
-
#do_GET(req, res) ⇒ Object
Performs a GET request.
-
#initialize(_server, cache) ⇒ CacheServlet
constructor
Creates a Cache Servlet.
Constructor Details
#initialize(_server, cache) ⇒ CacheServlet
Creates a Cache Servlet.
16 17 18 19 |
# File 'lib/sitediff/webserver/resultserver.rb', line 16 def initialize(_server, cache) super @cache = cache end |
Instance Method Details
#do_GET(req, res) ⇒ Object
Performs a GET request.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sitediff/webserver/resultserver.rb', line 23 def do_GET(req, res) path = req.path_info (md = %r{^/([^/]+)(/.*)$}.match(path)) || raise(WEBrick::HTTPStatus::NotFound) tag, path = *md.captures (r = @cache.get(tag.to_sym, path)) || raise(WEBrick::HTTPStatus::NotFound) raise WEBrick::HTTPStatus[r.error_code] if r.error_code raise WEBrick::HTTPStatus::InternalServerError, r.error if r.error res['content-type'] = 'text/html' res.body = r.content end |