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

Instance Method Summary collapse

Class Method Details

.cancel(request) ⇒ Object



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

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

.stream(response, &block) ⇒ Object

lazy decodes a grpc stream response



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) ⇒ Object

decodes a unary grpc response



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) ⇒ Object

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

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

Instance Method Details

#self?.cancelvoid

This method returns an undefined value.

Parameters:



11
# File 'sig/plugins/grpc/message.rbs', line 11

def self?.cancel: (Request) -> void

#self?void #self?Enumerable[String]

Overloads:

  • #self?void

    This method returns an undefined value.

    Parameters:

  • #self?Enumerable[String]

    Parameters:

    Returns:

    • (Enumerable[String])

Yields:

Yield Parameters:

  • arg0 (String)

Yield Returns:

  • (void)


8
9
# File 'sig/plugins/grpc/message.rbs', line 8

def self?.stream: (StreamResponse) { (String) -> void } -> void
| (StreamResponse) -> Enumerable[String]

#self?.unarygrpc_message

Parameters:

  • (response)

Returns:

  • (grpc_message)


6
# File 'sig/plugins/grpc/message.rbs', line 6

def self?.unary: (response) -> grpc_message

#self?.verify_statusvoid

This method returns an undefined value.

Parameters:



13
# File 'sig/plugins/grpc/message.rbs', line 13

def self?.verify_status: (StreamResponse | response) -> void