Class: QuickServe::Handlers::Snapshot
- Inherits:
-
Mongrel::HttpHandler
- Object
- Mongrel::HttpHandler
- QuickServe::Handlers::Snapshot
- Defined in:
- lib/quick_serve/handlers/snapshot.rb
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(url) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #process(request, response) ⇒ Object
Constructor Details
#initialize(url) ⇒ Snapshot
Returns a new instance of Snapshot.
5 6 7 8 9 10 11 12 |
# File 'lib/quick_serve/handlers/snapshot.rb', line 5 def initialize(url) @url = url @https = (url.match('https:') ? true : false) @host = url.gsub(/(http)(s*)(\:\/\/)/, '').split('/').first @snapshot = nil fetch super() end |
Instance Method Details
#fetch ⇒ Object
14 15 16 17 18 19 |
# File 'lib/quick_serve/handlers/snapshot.rb', line 14 def fetch require 'open-uri' @snapshot = open(@url).read host_root = (@https ? 'https://' : 'http://') + @host + '/' @snapshot.gsub!(/(href=|src=)(['"])(\/)/, "\\1\\2#{host_root}\\4") end |
#process(request, response) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/quick_serve/handlers/snapshot.rb', line 21 def process(request, response) response.start do |head,out| puts "quick_serve: served snapshot of #{@url}" head["Content-Type"] = "text/html" out << @snapshot end end |