Class: Protocol::GRPC::Middleware

Inherits:
HTTP::Middleware
  • Object
show all
Defined in:
lib/protocol/grpc/middleware.rb

Overview

Represents server middleware for handling gRPC requests. Implements Protocol::HTTP::Middleware interface. Subclasses should implement #dispatch to handle service routing and protocol details.

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ Middleware

Initialize a new middleware instance.



20
21
22
# File 'lib/protocol/grpc/middleware.rb', line 20

def initialize(app = nil)
	super(app)
end

Instance Method Details

#call(request) ⇒ Object

Handle incoming HTTP request.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/protocol/grpc/middleware.rb', line 27

def call(request)
	return super unless grpc_request?(request)
	
	# Ensure the request headers are using the gRPC header policy:
	request.headers.policy = Protocol::GRPC::HEADER_POLICY
	
	begin
		dispatch(request)
	rescue Error => error
		make_response(error.status_code, error.message, error: error)
	rescue StandardError => error
		make_response(Status::INTERNAL, error.message, error: error)
	end
end

#dispatch(request) ⇒ Object

Dispatch the request to the service handler. Subclasses should implement this method to handle routing and protocol details.

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/protocol/grpc/middleware.rb', line 47

def dispatch(request)
	raise NotImplementedError, "Subclasses must implement #dispatch"
end