You could also use these techniques to proxy pass any other kind of static assets, not only images. Remember that if your project has a lot of traffic, you would need to watch out for problems with rate limiting by your assets API provider. I’ve been using the NGINX based solution in Smart Wishlist for quite a while now to serve iTunes assets via SSL to both React based frontend and iOS apps. An advantage of this solution is that you don’t block your Ruby process and NGINX is better suited to handle multiple concurrent clients than Ruby servers. Resolver 8.8.8.8 line is needed to dynamically resolve DNS config of a target asset server and enable support for different assets hosts. Here is how you could send an asset part by part using Rack::Chunked middleware:Ĭ require "down" class App CHUNK_SIZE = 1024 * 128 # 128 KB def call ( env ) req = Rack :: Request. You can run Rack apps with a rackup command Assets streaming with Rack content_type, "Content-Length" => data_source.
Here’s how a simple Rails controller implementation could look like:Īpp/config/routes.rb get "/", to: "files#show"Īpp/controllers/files_controller.rb require "down" class FilesController data_source. You would need to include an asset location as a parameter of the request. In that case, a Rails app downloads an asset and sends it to the browser via a secure connection. Use Rails app as an SSL proxyĪnother solution would be to proxy an asset request through a Rails-based server. It also has a small memory footprint of less the 0.4 MB on load.
It provides a simple API for working with file downloads and supports more advanced techniques like streaming and caching. “down” gem for streaming supportĮach of the following examples uses down gem. Unfortunately, you have to take care of updating assets yourself (app icons could change at any time), and pay for all the bandwidth. An advantage of this approach is that traffic does not go through your servers, and assets can be cached using CloudFront CDN. In this case Amazon S3 with CloudFront could serve you well.
You could download all the required assets to deliver them via a secure connection. If you want to display this kind of insecure asset 2 on your webpage without browser warnings, here’s what you can do: Download assets and serve them via Amazon S3 You can check yourself: require "open-uri" require "json" JSON. At the time of writing this blog post, iTunes API does not officially 1 provide image assets via SSL. Until recently iTunes Store pages were displayed as insecure in the browsers because of http image assets.
In this blog post, I will explain how to setup Ruby and NGINX server to work as an SSL proxy for insecure content and describe some basic streaming techniques.ĭeveloper console and URL bar display insecure content warnings on. It’s enough that at least one of its resources is served without SSL. One potential problem is that website could be served via a secure SSL connection and still displayed as insecure by most of the modern browsers. SSL protection is becoming de facto standard in web and mobile development. A leading-edge performance and error monitoring tool for Ruby applications.