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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dassets/server/response.rb', line 13 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.to_s 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.
11 12 13 |
# File 'lib/dassets/server/response.rb', line 11 def asset_file @asset_file end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/dassets/server/response.rb', line 11 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/dassets/server/response.rb', line 11 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/dassets/server/response.rb', line 11 def status @status end |
Instance Method Details
#to_rack ⇒ Object
47 48 49 |
# File 'lib/dassets/server/response.rb', line 47 def to_rack [@status, @headers.to_hash, @body] end |