Class: Dassets::Server::Response
- Inherits:
-
Object
- Object
- Dassets::Server::Response
- Defined in:
- lib/dassets/server/response.rb
Instance Attribute Summary collapse
-
#asset_file ⇒ Object
readonly
Returns the value of attribute asset_file.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(env, asset_file) ⇒ Response
constructor
A new instance of Response.
- #to_rack ⇒ Object
Constructor Details
#initialize(env, asset_file) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dassets/server/response.rb', line 11 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 |
Instance Attribute Details
#asset_file ⇒ Object (readonly)
Returns the value of attribute asset_file.
9 10 11 |
# File 'lib/dassets/server/response.rb', line 9 def asset_file @asset_file end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/dassets/server/response.rb', line 9 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/dassets/server/response.rb', line 9 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/dassets/server/response.rb', line 9 def status @status end |
Instance Method Details
#to_rack ⇒ Object
32 33 34 |
# File 'lib/dassets/server/response.rb', line 32 def to_rack [@status, @headers.to_hash, @body] end |