Class: ThriftRack
- Inherits:
-
Object
- Object
- ThriftRack
- Defined in:
- lib/thrift_rack.rb,
lib/thrift_rack/atom.rb,
lib/thrift_rack/ping.rb,
lib/thrift_rack/client.rb,
lib/thrift_rack/logger.rb,
lib/thrift_rack/sentry.rb,
lib/thrift_rack/server.rb,
lib/thrift_rack/version.rb,
lib/thrift_rack/format_check.rb,
lib/thrift_rack/launch_timestamp.rb,
lib/thrift_rack/http_client_transport.rb
Defined Under Namespace
Classes: Atom, Client, FormatCheck, HttpClientTransport, LaunchTimestamp, Logger, Ping, Sentry, Server
Constant Summary collapse
- THRIFT_HEADER =
"application/x-thrift"- VERSION =
"0.2.5"
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.
18 19 20 21 22 23 24 |
# File 'lib/thrift_rack.rb', line 18 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
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/thrift_rack.rb', line 43 def self.app(servers = nil) Rack::Builder.new(ThriftRack.new(servers)) do use ThriftRack::LaunchTimestamp use ThriftRack::Ping use ThriftRack::FormatCheck use ThriftRack::Atom use ThriftRack::Logger use ThriftRack::Sentry if defined? Raven end end |
Instance Method Details
#call(env) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/thrift_rack.rb', line 26 def call(env) req = Rack::Request.new(env) Thread.current["request"] = req 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 ensure Thread.current["request"] = nil end |