Sha256: 3e4e8dc546ce272d1fe37d9a7de9118fdb6ae27ec678c2066891dabe4f134fae

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

require 'rack/proxy'

# This only exists so we can use Rack::Test to test the
# RackAdapter class, which assumes it's running on Thin

class ThinProxy < Rack::Proxy
  HOST = 'localhost'
  PORT = '8282'

  def initialize(rack_app)
    Thin::Logging.silent = true
    handler = Rack::Handler.get('thin')

    EM.stop if EM.reactor_running?
    Thread.pass while EM.reactor_running?

    Thread.new {
      handler.run(rack_app, :Host => HOST, :Port => PORT) do |server|
        @server = server
      end
    }
    Thread.pass until EM.reactor_running?
  end

  def stop
    EM.stop
    @server.stop
    Thread.pass while EM.reactor_running?
  end

  def rewrite_env(env)
    env['HTTP_HOST'] = HOST
    env['SERVER_PORT'] = PORT
    env[Faye::RackAdapter::HTTP_X_NO_CONTENT_LENGTH] = '1'
    env
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
faye-0.8.11 spec/thin_proxy.rb
face-faye-0.8.9 spec/thin_proxy.rb
faye-0.8.9 spec/thin_proxy.rb