Class: Plum::Rack::LegacySession

Inherits:
Object
  • Object
show all
Defined in:
lib/plum/rack/legacy_session.rb

Instance Method Summary collapse

Constructor Details

#initialize(svc, e, sock) ⇒ LegacySession

Returns a new instance of LegacySession.



7
8
9
10
11
12
# File 'lib/plum/rack/legacy_session.rb', line 7

def initialize(svc, e, sock)
  @svc = svc
  @e = e
  @sock = sock
  @config = svc.config
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/plum/rack/legacy_session.rb', line 14

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