Class: IntervalResponse::Invalid

Inherits:
Object
  • Object
show all
Includes:
ToRackResponseTriplet
Defined in:
lib/interval_response/invalid.rb

Overview

Serves out a response that is of size 0

Constant Summary collapse

ERROR_JSON =
'{"message": "Ranges cannot be satisfied"}'

Constants included from ToRackResponseTriplet

ToRackResponseTriplet::CHUNK_SIZE

Instance Method Summary collapse

Methods included from ToRackResponseTriplet

#to_rack_response_triplet

Constructor Details

#initialize(segment_map) ⇒ Invalid

Returns a new instance of Invalid.



7
8
9
# File 'lib/interval_response/invalid.rb', line 7

def initialize(segment_map)
  @interval_map = segment_map
end

Instance Method Details

#content_lengthObject



20
21
22
# File 'lib/interval_response/invalid.rb', line 20

def content_length
  ERROR_JSON.bytesize
end

#each {|ERROR_JSON, full_segment_range| ... } ⇒ Object

Yields:



11
12
13
14
# File 'lib/interval_response/invalid.rb', line 11

def each
  full_segment_range = (0..(ERROR_JSON.bytesize - 1))
  yield(ERROR_JSON, full_segment_range)
end

#headersObject



24
25
26
27
28
29
30
31
32
# File 'lib/interval_response/invalid.rb', line 24

def headers
  {
    'Accept-Ranges' => 'bytes',
    'Content-Length' => ERROR_JSON.bytesize.to_s,
    'Content-Type' => 'application/json',
    'Content-Range' => "bytes */#{@interval_map.size}",
    'ETag' => @interval_map.etag,
  }
end

#status_codeObject



16
17
18
# File 'lib/interval_response/invalid.rb', line 16

def status_code
  416
end