lib/threaded_proxy/controller.rb in rails-threaded-proxy-0.2.0 vs lib/threaded_proxy/controller.rb in rails-threaded-proxy-0.3.0
- old
+ new
@@ -1,10 +1,12 @@
+# frozen_string_literal: true
+
require_relative 'client'
module ThreadedProxy
module Controller
- def proxy_fetch(origin_url, options={})
+ def proxy_fetch(origin_url, options = {})
# hijack the response so we can take it outside of the rack request/response cycle
request.env['rack.hijack'].call
socket = request.env['rack.hijack_io']
Thread.new do
@@ -15,15 +17,13 @@
if request.env['HTTP_TRANSFER_ENCODING'] == 'chunked'
options[:headers]['Transfer-Encoding'] = 'chunked'
elsif request.env['CONTENT_LENGTH']
options[:headers]['content-length'] = request.env['CONTENT_LENGTH'].to_s
else
- raise "Cannot proxy a non-chunked POST request without content-length"
+ raise 'Cannot proxy a non-chunked POST request without content-length'
end
- if request.env['CONTENT_TYPE']
- options[:headers]['Content-Type'] = request.env['CONTENT_TYPE']
- end
+ options[:headers]['Content-Type'] = request.env['CONTENT_TYPE'] if request.env['CONTENT_TYPE']
end
client = Client.new(origin_url, options)
client.start(socket)
rescue Errno::EPIPE