Class: IntervalResponse::Single
- Inherits:
-
Object
- Object
- IntervalResponse::Single
- Includes:
- ToRackResponseTriplet
- Defined in:
- lib/interval_response/single.rb
Overview
Serves out a response that consists of one HTTP Range, which is always not the entire resource
Constant Summary
Constants included from ToRackResponseTriplet
ToRackResponseTriplet::CHUNK_SIZE
Instance Method Summary collapse
- #content_length ⇒ Object
-
#each ⇒ Object
Serve the part of the interval map.
- #headers ⇒ Object
-
#initialize(interval_map, http_ranges) ⇒ Single
constructor
A new instance of Single.
- #status_code ⇒ Object
Methods included from ToRackResponseTriplet
Constructor Details
#initialize(interval_map, http_ranges) ⇒ Single
Returns a new instance of Single.
6 7 8 9 |
# File 'lib/interval_response/single.rb', line 6 def initialize(interval_map, http_ranges) @interval_map = interval_map @http_range = http_ranges.first end |
Instance Method Details
#content_length ⇒ Object
22 23 24 |
# File 'lib/interval_response/single.rb', line 22 def content_length @http_range.end - @http_range.begin + 1 end |
#each ⇒ Object
Serve the part of the interval map
12 13 14 15 16 |
# File 'lib/interval_response/single.rb', line 12 def each @interval_map.each_in_range(@http_range) do |segment, range_in_segment| yield(segment, range_in_segment) end end |
#headers ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/interval_response/single.rb', line 26 def headers c_range = ('bytes %d-%d/%d' % [@http_range.begin, @http_range.end, @interval_map.size]) { 'Accept-Ranges' => 'bytes', 'Content-Length' => (@http_range.end - @http_range.begin + 1).to_s, 'Content-Type' => 'binary/octet-stream', 'Content-Range' => c_range, 'ETag' => @interval_map.etag, } end |
#status_code ⇒ Object
18 19 20 |
# File 'lib/interval_response/single.rb', line 18 def status_code 206 end |