
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Stream your data using HTTP/1.1 range requests and partial responses.
gem 'rstreamor', git: 'https://github.com/ndea/rstreamor.git', branch: 'master'
gem 'rstreamor', '~> 0.2.6'
bundle install
In combination with Carrierwave
class Profile < ActiveRecord::Base
mount_uploader :image_file, ProfileImageUploader
end
class VideosController < ApplicationController
include Rstreamor
def show
stream @resource.image_file
end
end
Rstreamor takes care of the rest. If you dont use Carrierwave as a file make sure your file method has the following methods defined:
Optionally, you could send some params to the stream
method like the following example:
class VideosController < ApplicationController
include Rstreamor
def show
stream @resource.image_file, { x_sendfile: true, stream: true }
end
end
Please note that if you don't specify any range request headers Rstreamor will return the whole file from byte 0 to EOF with status code 200
Byte serving is the process of sending only a portion of an HTTP/1.1 message from a server to a client. Byte serving begins when an HTTP server advertises its willingness to serve partial requests using the Accept-Ranges response header. A client then requests a specific part of a file from the server using the Range request header. If the range is valid, the server sends it to the client with a 206 Partial Content status code and a Content-Range header listing the range sent. Clients which request byte-serving might do so in cases in which a large file has been only partially delivered and a limited portion of the file is needed in a particular range. Byte Serving is therefore a method of bandwidth optimization. Wikipedia
Consider you have a large video or audio file on your server which needs to be served partially to your client. You don't want to send the whole file in one response (unless you want to download the file). Instead the client needs only partial content which he can view and request other partial content if needed. Rstreamor provides this byte serving mechanism defined in HTTP/1.1.
Example of the request - response flow Consider simple HTML5 video streaming.
<video width="320" height="240" controls>
<source src="http://..." type="video/mp4">
Your browser does not support the video tag.
</video>
The first request fired by the client contains the following header
Range:bytes=0-
and requests the whole file from the server starting from 0 till end. The server then responds with the following headers
Accept-Ranges:bytes
Cache-Control:no-cache
Content-Disposition:inline
Content-Length:6642801
Content-Range:bytes 0-6642800/6642801
Content-Transfer-Encoding:binary
Content-Type:application/mp4
Now let's skip through our video and seek for a certain scene - the client now sends the following request header
Range:bytes=3303604-
And the server responds with the following response headers
Accept-Ranges:bytes
Cache-Control:no-cache
Content-Disposition:inline
Content-Length:3339197
Content-Range:bytes 3303604-6642800/6642801
Content-Transfer-Encoding:binary
Content-Type:application/mp4
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that rstreamor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.