Encoding module for GRPC
responses
Can encode and decode grpc messages.
Public Instance methods
cancel(request)
[show source]
# File lib/httpx/plugins/grpc/message.rb 34 def cancel(request) 35 request.emit(:refuse, :client_cancellation) 36 end
stream(response, &block)
lazy decodes a grpc stream response
[show source]
# File lib/httpx/plugins/grpc/message.rb 22 def stream(response, &block) 23 return enum_for(__method__, response) unless block 24 25 decoder = Transcoder::GRPCEncoding.decode(response) 26 27 response.each do |frame| 28 decoder.call(frame, &block) 29 end 30 31 verify_status(response) 32 end
unary(response)
decodes a unary grpc response
[show source]
# File lib/httpx/plugins/grpc/message.rb 13 def unary(response) 14 verify_status(response) 15 16 decoder = Transcoder::GRPCEncoding.decode(response) 17 18 decoder.call(response.to_s) 19 end
verify_status(response)
interprets the grpc call trailing metadata, and raises an exception in case of error code
[show source]
# File lib/httpx/plugins/grpc/message.rb 40 def verify_status(response) 41 # return standard errors if need be 42 response.raise_for_status 43 44 status = Integer(response.headers["grpc-status"]) 45 message = response.headers["grpc-message"] 46 47 return if status.zero? 48 49 response.close 50 raise GRPCError.new(status, message, response.trailing_metadata) 51 end