Class: Dassets::Server::Response
- Inherits:
-
Object
- Object
- Dassets::Server::Response
- Defined in:
- lib/dassets/server/response.rb
Defined Under Namespace
Classes: Body
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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dassets/server/response.rb', line 12 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('Last-Modified' => mtime), [] ] elsif !@asset_file.exists? [ 404, Rack::Utils::HeaderHash.new, ["Not Found"] ] else @asset_file.digest! body = Body.new(env, @asset_file) [ body.partial? ? 206 : 200, Rack::Utils::HeaderHash.new.merge(@asset_file.response_headers).tap do |h| h['Last-Modified'] = mtime h['Content-Type'] = @asset_file.mime_type.to_s h['Content-Length'] = body.size.to_s h['Content-Range'] = body.content_range if body.partial? end, env["REQUEST_METHOD"] == "HEAD" ? [] : body ] end end |
Instance Attribute Details
#asset_file ⇒ Object (readonly)
Returns the value of attribute asset_file.
10 11 12 |
# File 'lib/dassets/server/response.rb', line 10 def asset_file @asset_file end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/dassets/server/response.rb', line 10 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/dassets/server/response.rb', line 10 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/dassets/server/response.rb', line 10 def status @status end |
Instance Method Details
#to_rack ⇒ Object
35 36 37 |
# File 'lib/dassets/server/response.rb', line 35 def to_rack [@status, @headers.to_hash, @body] end |