Class: IntervalResponse::Single
- 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
Instance Method Summary collapse
- #content_length ⇒ Object
-
#each ⇒ Object
Serve the part of the interval map.
- #headers ⇒ Object
-
#initialize(interval_sequence, http_range) ⇒ Single
constructor
A new instance of Single.
- #satisfied_with_first_interval? ⇒ Boolean
- #status_code ⇒ Object
Methods inherited from Abstract
#etag, #multiple_ranges?, #to_rack_response_triplet
Constructor Details
#initialize(interval_sequence, http_range) ⇒ Single
Returns a new instance of Single.
5 6 7 8 |
# File 'lib/interval_response/single.rb', line 5 def initialize(interval_sequence, http_range) @interval_sequence = interval_sequence @http_range = http_range end |
Instance Method Details
#content_length ⇒ Object
21 22 23 |
# File 'lib/interval_response/single.rb', line 21 def content_length @http_range.end - @http_range.begin + 1 end |
#each ⇒ Object
Serve the part of the interval map
11 12 13 14 15 |
# File 'lib/interval_response/single.rb', line 11 def each @interval_sequence.each_in_range(@http_range) do |segment, range_in_segment| yield(segment, range_in_segment) end end |
#headers ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/interval_response/single.rb', line 25 def headers c_range = ('bytes %d-%d/%d' % [@http_range.begin, @http_range.end, @interval_sequence.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' => etag, } end |
#satisfied_with_first_interval? ⇒ Boolean
36 37 38 |
# File 'lib/interval_response/single.rb', line 36 def satisfied_with_first_interval? @interval_sequence.first_interval_only?(@http_range) end |
#status_code ⇒ Object
17 18 19 |
# File 'lib/interval_response/single.rb', line 17 def status_code 206 end |