Class: THTP::NullRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/thtp/server/null_route.rb

Overview

A THTP middleware stack terminator, telling clients they’ve done something wrong if their requests weren’t captured by a running server

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

if a request makes it here, it’s bad; tell the caller what it should have done



14
15
16
17
18
19
20
# File 'lib/thtp/server/null_route.rb', line 14

def call(env)
  # default to CompactProtocol because we need a protocol with which to send back errors
  protocol = Encoding.protocol(Rack::Request.new(env).media_type) || Thrift::JsonProtocol
  headers = { Rack::CONTENT_TYPE => Encoding.content_type(protocol) }
  body = Utils.serialize_buffer(BadRequestError.new.to_thrift, protocol)
  [Status::EXCEPTION, headers, [body]]
end