Module: GRPCWeb::RackHandler

Extended by:
ContentTypes
Defined in:
lib/grpc_web/server/rack_handler.rb

Overview

Placeholder

Constant Summary collapse

NOT_FOUND =
404
UNSUPPORTED_MEDIA_TYPE =
415
INTERNAL_SERVER_ERROR =
500
ACCEPT_HEADER =
'HTTP_ACCEPT'

Constants included from ContentTypes

ContentTypes::ALL_CONTENT_TYPES, ContentTypes::BASE64_CONTENT_TYPES, ContentTypes::DEFAULT_CONTENT_TYPE, ContentTypes::JSON_CONTENT_TYPE, ContentTypes::PROTO_CONTENT_TYPE, ContentTypes::TEXT_CONTENT_TYPE, ContentTypes::TEXT_PROTO_CONTENT_TYPE, ContentTypes::UNSPECIFIED_CONTENT_TYPES

Class Method Summary collapse

Class Method Details

.call(service, service_method, env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/grpc_web/server/rack_handler.rb', line 21

def call(service, service_method, env)
  rack_request = Rack::Request.new(env)
  return not_found_response(rack_request.path) unless rack_request.post?
  return unsupported_media_type_response unless valid_content_types?(rack_request)

  content_type = rack_request.content_type
  accept = rack_request.get_header(ACCEPT_HEADER)
  body = rack_request.body.read
  request = GRPCWeb::GRPCWebRequest.new(service, service_method, content_type, accept, body)
  response = GRPCWeb::GRPCRequestProcessor.process(request)

  [200, { 'Content-Type' => response.content_type }, [response.body]]
rescue Google::Protobuf::ParseError => e
  invalid_response(e.message)
rescue StandardError => e
  ::GRPCWeb.on_error.call(e, service, service_method)
  error_response
end