Class: Thrift::ThinHTTPServer::RackApplication

Inherits:
Object
  • Object
show all
Defined in:
lib/thrift/server/thin_http_server.rb

Constant Summary collapse

THRIFT_HEADER =
"application/x-thrift"

Class Method Summary collapse

Class Method Details

.failed_requestObject



80
81
82
# File 'lib/thrift/server/thin_http_server.rb', line 80

def self.failed_request
  Rack::Response.new(['Not Found'], 404, {'Content-Type' => THRIFT_HEADER})
end

.for(path, processor, protocol_factory) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/thrift/server/thin_http_server.rb', line 54

def self.for(path, processor, protocol_factory)
  Rack::Builder.new do
    use Rack::CommonLogger
    use Rack::ShowExceptions
    use Rack::Lint
    map path do
      run lambda { |env|
        request = Rack::Request.new(env)
        if RackApplication.valid_thrift_request?(request)
          RackApplication.successful_request(request, processor, protocol_factory)
        else
          RackApplication.failed_request
        end
      }
    end
  end
end

.successful_request(rack_request, processor, protocol_factory) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/thrift/server/thin_http_server.rb', line 72

def self.successful_request(rack_request, processor, protocol_factory)
  response = Rack::Response.new([], 200, {'Content-Type' => THRIFT_HEADER})
  transport = IOStreamTransport.new rack_request.body, response
  protocol = protocol_factory.get_protocol transport
  processor.process protocol, protocol
  response
end

.valid_thrift_request?(rack_request) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/thrift/server/thin_http_server.rb', line 84

def self.valid_thrift_request?(rack_request)
  rack_request.post? && rack_request.env["CONTENT_TYPE"] == THRIFT_HEADER
end