Class: Rstreamor::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rstreamor/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Response

Returns a new instance of Response.



5
6
7
# File 'lib/rstreamor/response.rb', line 5

def initialize(request)
  self.request = request
end

Instance Attribute Details

#requestObject

Returns the value of attribute request.



3
4
5
# File 'lib/rstreamor/response.rb', line 3

def request
  @request
end

Instance Method Details

#accept_rangesObject



25
26
27
# File 'lib/rstreamor/response.rb', line 25

def accept_ranges
  'bytes'
end

#cache_controlObject



29
30
31
# File 'lib/rstreamor/response.rb', line 29

def cache_control
  'no-cache'
end

#content_lengthObject



13
14
15
16
17
18
19
# File 'lib/rstreamor/response.rb', line 13

def content_length
  if self.request.range_header?
    (self.request.upper_bound - self.request.lower_bound).to_s
  else
    self.request.file.data.size
  end
end

#content_rangeObject



21
22
23
# File 'lib/rstreamor/response.rb', line 21

def content_range
  "bytes #{self.request.lower_bound}-#{self.request.upper_bound - 1}/#{self.request.file.data.size}"
end

#response_codeObject



9
10
11
# File 'lib/rstreamor/response.rb', line 9

def response_code
  self.request.range_header? ? 206 : 200
end