Protocol::GRPCSourceProtocolGRPCHeaderStatus

class Status

The grpc-status header represents the gRPC status code.

The grpc-status header contains a numeric status code (0-16) indicating the result of the RPC call. Status code 0 indicates success (OK), while other codes indicate various error conditions. This header can appear both as an initial header (for trailers-only responses) and as a trailer.

Definitions

def initialize(value)

Initialize the status header with the given value.

Signature

parameter value String, Integer, Array

The status code as a string, integer, or array (takes first element).

Implementation

def initialize(value)
	@value = normalize_value(value)
end

def to_i

Get the status code as an integer.

Signature

returns Integer

The status code.

Implementation

def to_i
	@value
end

def to_s

Serialize the status code to a string.

Signature

returns String

The status code as a string.

Implementation

def to_s
	@value.to_s
end

def <<(value)

Merge another status value (takes the new value, as status should only appear once)

Signature

parameter value String, Integer, Array

The new status code

Implementation

def <<(value)
	@value = normalize_value(value)
	self
end

def normalize_value(value)

Normalize a value to an integer status code. Handles arrays (from external clients), strings, and integers.

Signature

parameter value String, Integer, Array

The raw value

returns Integer

The normalized status code

Implementation

def normalize_value(value)
	# Handle Array case (may occur with external clients)
	actual_value = value.is_a?(Array) ? value.flatten.compact.first : value
	actual_value.to_i
end

def self.trailer?

Whether this header is acceptable in HTTP trailers. The grpc-status header can appear in trailers as per the gRPC specification.

Signature

returns Boolean

true, as grpc-status can appear in trailers.

Implementation

def self.trailer?
	true
end