Class: ServeByteRange::MultipartByteRangesBody
- Inherits:
-
ByteRangeBody
- Object
- ByteRangeBody
- ServeByteRange::MultipartByteRangesBody
- Defined in:
- lib/serve_byte_range.rb
Overview
Instance Method Summary collapse
- #content_length ⇒ Object
- #content_type ⇒ Object
- #each {|trailer| ... } ⇒ Object
- #headers ⇒ Object
-
#initialize(http_ranges:, boundary:, **params_for_single_range, &serving_block) ⇒ MultipartByteRangesBody
constructor
A new instance of MultipartByteRangesBody.
Methods inherited from ByteRangeBody
Constructor Details
#initialize(http_ranges:, boundary:, **params_for_single_range, &serving_block) ⇒ MultipartByteRangesBody
123 124 125 126 127 |
# File 'lib/serve_byte_range.rb', line 123 def initialize(http_ranges:, boundary:, **params_for_single_range, &serving_block) super(http_range: http_ranges.first, **params_for_single_range) @http_ranges = http_ranges @boundary = boundary end |
Instance Method Details
#content_length ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/serve_byte_range.rb', line 139 def content_length # The Content-Length of a multipart response includes the length # of all the ranges of the resource, but also the lengths of the # multipart part headers - which we need to precompute. To do it # we need to run through all of our ranges and output some strings, # and if a lot of ranges are involved this can get expensive. So # memoize the envelope size (it never changes between calls) @envelope_size ||= compute_envelope_size end |
#content_type ⇒ Object
149 150 151 |
# File 'lib/serve_byte_range.rb', line 149 def content_type "multipart/byteranges; boundary=#{@boundary}" end |
#each {|trailer| ... } ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/serve_byte_range.rb', line 129 def each(&blk) @http_ranges.each_with_index do |range, part_i| yield(part_header(range, part_i)) writable_for_range_bytes = BlockWritableWithLimit.new(range.size, &blk) @serving_block.call(range, writable_for_range_bytes) writable_for_range_bytes.verify! end yield(trailer) end |
#headers ⇒ Object
153 154 155 156 157 |
# File 'lib/serve_byte_range.rb', line 153 def headers super.tap do |hh| hh.delete("Content-Range") end end |