Class: ThriftRack
- Inherits:
-
Object
- Object
- ThriftRack
- Defined in:
- lib/thrift_rack.rb,
lib/thrift_rack/ping.rb,
lib/thrift_rack/client.rb,
lib/thrift_rack/logger.rb,
lib/thrift_rack/server.rb,
lib/thrift_rack/version.rb,
lib/thrift_rack/format_check.rb,
lib/thrift_rack/http_client_transport.rb
Defined Under Namespace
Classes: Client, FormatCheck, HttpClientTransport, Logger, Ping, Server
Constant Summary collapse
- THRIFT_HEADER =
"application/x-thrift"
- VERSION =
"0.2.4"
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(servers = nil) ⇒ ThriftRack
constructor
A new instance of ThriftRack.
Constructor Details
#initialize(servers = nil) ⇒ ThriftRack
Returns a new instance of ThriftRack.
15 16 17 18 19 20 21 |
# File 'lib/thrift_rack.rb', line 15 def initialize(servers = nil) servers ||= ThriftRack::Server.children @maps = {} servers.each do |server| @maps[server.mount_path] = server end end |
Class Method Details
.app(servers = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/thrift_rack.rb', line 37 def self.app(servers = nil) Rack::Builder.new(ThriftRack.new(servers)) do use ThriftRack::Ping use ThriftRack::FormatCheck use ThriftRack::Logger end end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/thrift_rack.rb', line 23 def call(env) req = Rack::Request.new(env) server_class = @maps[req.path] return Rack::Response.new(["No Thrift Server For #{req.path}"], 404, {'Content-Type' => 'text/plain'}) unless server_class resp = Rack::Response.new([], 200, {'Content-Type' => THRIFT_HEADER}) transport = Thrift::IOStreamTransport.new req.body, resp protocol = server_class.protocol_factory.get_protocol transport server_class.processor_class.new(server_class.new).process(protocol, protocol) resp end |