aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum/rack/legacy_session.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plum/rack/legacy_session.rb')
-rw-r--r--lib/plum/rack/legacy_session.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/plum/rack/legacy_session.rb b/lib/plum/rack/legacy_session.rb
new file mode 100644
index 0000000..6712933
--- /dev/null
+++ b/lib/plum/rack/legacy_session.rb
@@ -0,0 +1,36 @@
+# -*- frozen-string-literal: true -*-
+using Plum::BinaryString
+
+module Plum
+ module Rack
+ class LegacySession
+ def initialize(svc, e, sock)
+ @svc = svc
+ @e = e
+ @sock = sock
+ @config = svc.config
+ end
+
+ def run
+ if @config[:fallback_legacy_host]
+ @logger.info "legacy HTTP: fallbacking to: #{@config[:fallback_legacy_host]}:#{@config[:fallback_legacy_port]}"
+ upstream = TCPSocket.open(@config[:fallback_legacy_host], @config[:fallback_legacy_port])
+ upstream.write(@e.buf) if @e.buf
+ loop do
+ ret = IO.select([@sock, upstream])
+ ret[0].each { |s|
+ a = s.readpartial(65536)
+ if s == upstream
+ @sock.write(a)
+ else
+ upstream.write(a)
+ end
+ }
+ end
+ end
+ ensure
+ upstream.close if upstream
+ end
+ end
+ end
+end