Sha256: 97d22176340833bcc1ffcadfd33c856c176326af21c62ad2ec5212c4ec025a53
Contents?: true
Size: 957 Bytes
Versions: 8
Compression:
Stored size: 957 Bytes
Contents
require 'rack/response' require 'rack/utils' require 'rack/mime' module Dassets; end class Dassets::Server class Response attr_reader :asset_file, :status, :headers, :body def initialize(env, asset_file) @asset_file = asset_file mtime = @asset_file.mtime.to_s @status, @headers, @body = if env['HTTP_IF_MODIFIED_SINCE'] == mtime [ 304, Rack::Utils::HeaderHash.new, [] ] elsif !@asset_file.exists? [ 404, Rack::Utils::HeaderHash.new, ["Not Found"] ] else @asset_file.digest! [ 200, Rack::Utils::HeaderHash.new.tap do |h| h["Content-Type"] = @asset_file.mime_type.to_s h["Content-Length"] = @asset_file.size.to_s h["Last-Modified"] = mtime end, env["REQUEST_METHOD"] == "HEAD" ? [] : [ @asset_file.content ] ] end end def to_rack [@status, @headers.to_hash, @body] end end end
Version data entries
8 entries across 8 versions & 1 rubygems