Class: Protocol::GRPC::Header::Message

Inherits:
String
  • Object
show all
Defined in:
lib/protocol/grpc/header/message.rb

Overview

The grpc-message header represents the gRPC status message.

The grpc-message header contains a human-readable error message, URL-encoded according to RFC 3986. This header is optional and typically only present when there's an error (non-zero status code). This header can appear both as an initial header (for trailers-only responses) and as a trailer.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Message

Initialize the message header with the given value.



42
43
44
# File 'lib/protocol/grpc/header/message.rb', line 42

def initialize(value)
	super(value)
end

Class Method Details

.coerce(value) ⇒ Object

Coerce a value to a Message instance. Used by Protocol::HTTP::Headers when setting header values. Automatically encodes the message for transmission.



31
32
33
34
35
36
37
# File 'lib/protocol/grpc/header/message.rb', line 31

def self.coerce(value)
	if value.is_a?(self)
		value
	else
		new(encode(value.to_s))
	end
end

.encode(message) ⇒ Object

Encode the message for use in headers.



57
58
59
# File 'lib/protocol/grpc/header/message.rb', line 57

def self.encode(message)
	URI.encode_www_form_component(message).gsub("+", "%20")
end

.parse(value) ⇒ Object

Parse a message from a header value.



21
22
23
# File 'lib/protocol/grpc/header/message.rb', line 21

def self.parse(value)
	new(value)
end

.trailer?Boolean

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

Returns:

  • (Boolean)


72
73
74
# File 'lib/protocol/grpc/header/message.rb', line 72

def self.trailer?
	true
end

Instance Method Details

#<<(value) ⇒ Object

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



63
64
65
66
67
# File 'lib/protocol/grpc/header/message.rb', line 63

def <<(value)
	replace(value.to_s)
	
	return self
end

#decodeObject

Decode the URL-encoded message.



49
50
51
# File 'lib/protocol/grpc/header/message.rb', line 49

def decode
	::URI.decode_www_form_component(self)
end