Module: HTTPX::Plugins::GRPC::Message

Defined in:
lib/httpx/plugins/grpc/message.rb,
sig/plugins/grpc/message.rbs

Overview

Encoding module for GRPC responses

Can encode and decode grpc messages.

Class Method Summary collapse

Class Method Details

.cancel(request) ⇒ void

This method returns an undefined value.

Parameters:



34
35
36
# File 'lib/httpx/plugins/grpc/message.rb', line 34

def cancel(request)
  request.emit(:refuse, :client_cancellation)
end

.stream(arg0) ⇒ void .stream(arg0) ⇒ Enumerable[String]

lazy decodes a grpc stream response

Overloads:

  • .stream(arg0) ⇒ void

    This method returns an undefined value.

    Parameters:

  • .stream(arg0) ⇒ Enumerable[String]

    Parameters:

    Returns:

    • (Enumerable[String])

Yields:

Yield Parameters:

  • arg0 (String)

Yield Returns:

  • (void)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/httpx/plugins/grpc/message.rb', line 22

def stream(response, &block)
  return enum_for(__method__, response) unless block

  decoder = Transcoder::GRPCEncoding.decode(response)

  response.each do |frame|
    decoder.call(frame, &block)
  end

  verify_status(response)
end

.unary(response) ⇒ grpc_message

decodes a unary grpc response

Parameters:

  • (response)

Returns:

  • (grpc_message)


13
14
15
16
17
18
19
# File 'lib/httpx/plugins/grpc/message.rb', line 13

def unary(response)
  verify_status(response)

  decoder = Transcoder::GRPCEncoding.decode(response)

  decoder.call(response.to_s)
end

.verify_status(response) ⇒ void

This method returns an undefined value.

interprets the grpc call trailing metadata, and raises an exception in case of error code

Parameters:

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/httpx/plugins/grpc/message.rb', line 40

def verify_status(response)
  # return standard errors if need be
  response.raise_for_status

  status = Integer(response.headers["grpc-status"])
  message = response.headers["grpc-message"]

  return if status.zero?

  response.close
  raise GRPCError.new(status, message, response.)
end