Sha256: ec5b85a265eee41b28d55496427e99b2a4c0fbfea7b5d6be430b31218ff94a28
Contents?: true
Size: 937 Bytes
Versions: 3
Compression:
Stored size: 937 Bytes
Contents
require 'rack/response' require 'rack/utils' require 'rack/mime' 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dassets-0.6.0 | lib/dassets/server/response.rb |
dassets-0.5.0 | lib/dassets/server/response.rb |
dassets-0.4.1 | lib/dassets/server/response.rb |