Sha256: dbc2dbb1c435de51a6bb5ad3182c121b25a11eb9db9aed0e7052ee650a39710c

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

require "eventmachine"
require "uri"

require "hatetepe/client"

module Hatetepe
  class Proxy
    attr_reader :app, :env
    
    def initialize(app)
      @app = app
    end
    
    def call(env)
      @env = env
      env["proxy.start"] = method(:start)
      
      app.call env
    end
    
    def start(target)
      uri = build_uri(target)
      
      env.delete "proxy.start"
      env["proxy.callback"] ||= method(:callback)
      
      response = Client.request(verb, uri, headers)
      env["proxy.callback"].call @response, env
    end
    
    def callback(response, env)
      response
    end
  end
end

module Hatetepe
  class OldProxy
    attr_reader :env, :target
    
    def initialize(env, target)
      client = EM.connect target.host, target.port, Client
      client.request env["rity.request"].verb, env["rity.request"].uri
      
      env["proxy.callback"] ||= proc {|response|
        env["proxy.start_reverse"].call response
      }
      env["proxy.start_reverse"] = proc {|response|
        env["stream.start"].call *response[0..1]
        env["stream.send_raw"].call client.requests
      }
    end
    
    def initialize(env, target)
      response = Client.request(env["rity.request"])
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hatetepe-0.2.4 lib/hatetepe/proxy.rb
hatetepe-0.2.3 lib/hatetepe/proxy.rb
hatetepe-0.2.2 lib/hatetepe/proxy.rb
hatetepe-0.2.1 lib/hatetepe/proxy.rb
hatetepe-0.2.0 lib/hatetepe/proxy.rb