module GRPCWeb::GRPCRequestProcessor

Placeholder

Public Class Methods

process(grpc_web_request) click to toggle source
# File lib/grpc_web/server/grpc_request_processor.rb, line 15
def process(grpc_web_request)
  text_coder = ::GRPCWeb::TextCoder
  framing = ::GRPCWeb::RequestFraming
  serialization = ::GRPCWeb::MessageSerialization

  grpc_web_request = text_coder.decode_request(grpc_web_request)
  grpc_web_request = framing.unframe_request(grpc_web_request)
  grpc_web_request = serialization.deserialize_request(grpc_web_request)
  grpc_web_response = execute_request(grpc_web_request)
  grpc_web_response = serialization.serialize_response(grpc_web_response)
  grpc_web_response = framing.frame_response(grpc_web_response)
  text_coder.encode_response(grpc_web_response)
end

Private Class Methods

execute_request(request) click to toggle source
# File lib/grpc_web/server/grpc_request_processor.rb, line 31
def execute_request(request)
  service_method = ::GRPC::GenericService.underscore(request.service_method.to_s)

  begin
    response = request.service.send(service_method, request.body)
  rescue StandardError => e
    ::GRPCWeb.on_error.call(e, request.service, request.service_method)
    response = e # Return exception as body if one is raised
  end
  ::GRPCWeb::GRPCWebResponse.new(response_content_type(request), response)
end
response_content_type(request) click to toggle source

Use Accept header value if specified, otherwise use request content type

# File lib/grpc_web/server/grpc_request_processor.rb, line 44
def response_content_type(request)
  if UNSPECIFIED_CONTENT_TYPES.include?(request.accept)
    request.content_type
  else
    request.accept
  end
end