Rails5でRackのmiddleware.use
を使用して新しいドメインにリダイレクトさせたい場合、Content-Length
は何を返すべきでしょうか。
現在request_redirector.rb
をいうファイルを作成して、herokuにアップしているプロジェクトを301リダイレクトさせようとしています。
config/environments/production.rb
1Rails.application.configure do 2(中略) 3 config.middleware.use 'RequestRedirector' 4end 5
lib/request_redirector.rb
1Class RequestRedirector 2 OLD_DOMAIN = 'OLD_DOMAIN' 3 NEW_DOMAIN = 'NEW_DOMAIN' 4 5 def initialize(app) 6 @app = app 7 end 8 9 def call(env) 10 request = Rack::Request.new(env) 11 12 if request.host.starts_with?(OLD_DOMAIN) 13 location = request.url.sub(OLD_DOMAIN + ".herokuapp.com", NEW_DOMAIN) 14 [301, { "Location" => location, "Content-Type" => 'text/html', "Content-Length" => '0'}, []] 15 else 16 @app.call(env) 17 end 18 end 19end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/31 11:51