У меня есть промежуточное ПО этого класса:
class RedirectIt
require "net/https"
require "uri"
require 'open-uri'
APP_DOMAIN = 'http://www.mydomain.com'
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
response = Rack::Response.new(env)
response.headers['Cache-Control'] = "public, max-age=#{84.hours.to_i}"
response.headers['Content-Type'] = 'image/png'
response.headers['Content-Disposition'] = 'inline'
response.body = "#{open('http://s3-eu-west-1.amazonaws.com/bucket/asdas.png').read}"
end
end
Проблема только в том, что он выдает ошибку:
Started GET "/?view=boks" for 127.0.0.1 at 2012-04-01 04:07:58 +0200
NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]=):
Я что-то не так делаю?Я попытался переписать этот код, который я имел в контроллере:
def image_proxy
image_url = "http://s3-eu-west-1.amazonaws.com/bucket#{request.path}"
response.headers['Cache-Control'] = "public, max-age=#{84.hours.to_i}"
response.headers['Content-Type'] = 'image/png'
response.headers['Content-Disposition'] = 'inline'
render :text => open(image_url, "rb").read
end