protocol-grpc 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/grpc/header/message.rb +14 -0
- data/lib/protocol/grpc/header/status.rb +13 -0
- data/lib/protocol/grpc/metadata.rb +20 -4
- data/lib/protocol/grpc/middleware.rb +1 -1
- data/lib/protocol/grpc/version.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 506e98d8cefc5e0357e9e59331d2fd1c8e6ee830b08ccade7650e5e1956dbd83
|
|
4
|
+
data.tar.gz: f1dfa3ff52d82e1c9db41d3536864107cc1bbe58de4a0d4ee4cec0021862b739
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c41ddca4368db85c9d18d9c327147104f2a8c62193b9e4488ff90d662a94bc37bb875bb43e19285b093d5554377bc28fd6c4595e447684a984bbc7cb480d841e
|
|
7
|
+
data.tar.gz: 67935af35d49bc8227280862b82c1823e43fc065487d59fa19759e293d7d6c3569b9955b4c621ae16b202dbb17288fbc2680ff9a7ea0659c28a1f35208bdd82b
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -22,6 +22,20 @@ module Protocol
|
|
|
22
22
|
new(value)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# Coerce a value to a Message instance.
|
|
26
|
+
# Used by Protocol::HTTP::Headers when setting header values.
|
|
27
|
+
# Automatically encodes the message for transmission.
|
|
28
|
+
#
|
|
29
|
+
# @parameter value [Object] The value to coerce (will be encoded if not already a Message).
|
|
30
|
+
# @returns [Message] A new Message instance with encoded content.
|
|
31
|
+
def self.coerce(value)
|
|
32
|
+
if value.is_a?(self)
|
|
33
|
+
value
|
|
34
|
+
else
|
|
35
|
+
new(encode(value.to_s))
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
25
39
|
# Initialize the message header with the given value.
|
|
26
40
|
#
|
|
27
41
|
# @parameter value [String] The message value (will be URL-encoded if not already encoded).
|
|
@@ -20,6 +20,19 @@ module Protocol
|
|
|
20
20
|
new(value.to_i)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# Coerce a value to a Status instance.
|
|
24
|
+
# Used by Protocol::HTTP::Headers when setting header values.
|
|
25
|
+
#
|
|
26
|
+
# @parameter value [Object] The value to coerce (integer or string status code).
|
|
27
|
+
# @returns [Status] A new Status instance.
|
|
28
|
+
def self.coerce(value)
|
|
29
|
+
if value.is_a?(self)
|
|
30
|
+
value
|
|
31
|
+
else
|
|
32
|
+
new(value)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
23
36
|
# Initialize the status header with the given value.
|
|
24
37
|
#
|
|
25
38
|
# @parameter value [String | Integer] The status code as a string or integer.
|
|
@@ -75,23 +75,39 @@ module Protocol
|
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
#
|
|
78
|
+
# Assign gRPC status, message, and optional backtrace to headers.
|
|
79
|
+
#
|
|
79
80
|
# Whether these become headers or trailers is controlled by the protocol layer.
|
|
81
|
+
#
|
|
80
82
|
# @parameter headers [Protocol::HTTP::Headers]
|
|
81
83
|
# @parameter status [Integer] gRPC status code
|
|
82
84
|
# @parameter message [String | Nil] Optional status message
|
|
83
85
|
# @parameter error [Exception | Nil] Optional error object (used to extract backtrace)
|
|
84
|
-
def self.
|
|
85
|
-
headers["grpc-status"] =
|
|
86
|
-
|
|
86
|
+
def self.assign_status!(headers, status: Status::OK, message: nil, error: nil)
|
|
87
|
+
headers["grpc-status"] = status
|
|
88
|
+
|
|
89
|
+
if error && message.nil?
|
|
90
|
+
# If message is not provided but error is, use error message
|
|
91
|
+
message = error.message
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
if message
|
|
95
|
+
headers["grpc-message"] = message
|
|
96
|
+
end
|
|
87
97
|
|
|
88
98
|
# Add backtrace from error if available
|
|
89
99
|
if error && error.backtrace && !error.backtrace.empty?
|
|
90
100
|
# Assign backtrace array directly - Split header will handle it
|
|
91
101
|
headers["backtrace"] = error.backtrace
|
|
92
102
|
end
|
|
103
|
+
|
|
104
|
+
return headers
|
|
93
105
|
end
|
|
94
106
|
|
|
107
|
+
class << self
|
|
108
|
+
# Backward compatibility alias
|
|
109
|
+
alias add_status! assign_status!
|
|
110
|
+
end
|
|
95
111
|
end
|
|
96
112
|
end
|
|
97
113
|
end
|
|
@@ -67,7 +67,7 @@ module Protocol
|
|
|
67
67
|
headers = Protocol::HTTP::Headers.new([], nil, policy: HEADER_POLICY)
|
|
68
68
|
headers["content-type"] = "application/grpc+proto"
|
|
69
69
|
|
|
70
|
-
Metadata.
|
|
70
|
+
Metadata.assign_status!(headers, status: status_code, message: message, error: error)
|
|
71
71
|
|
|
72
72
|
Protocol::HTTP::Response[200, headers, nil]
|
|
73
73
|
end
|
data/readme.md
CHANGED
|
@@ -28,6 +28,10 @@ Please see the [project documentation](https://socketry.github.io/protocol-grpc/
|
|
|
28
28
|
|
|
29
29
|
Please see the [project releases](https://socketry.github.io/protocol-grpc/releases/index) for all releases.
|
|
30
30
|
|
|
31
|
+
### v0.11.0
|
|
32
|
+
|
|
33
|
+
- Rename `add_status!` to `assign_status!` to better reflect its purpose of assigning status information to headers or trailers.
|
|
34
|
+
|
|
31
35
|
### v0.5.0
|
|
32
36
|
|
|
33
37
|
- Server-side errors now automatically include backtraces in response headers when an error object is provided. Backtraces are transmitted as arrays via Split headers and can be extracted by clients.
|
data/releases.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
+
## v0.11.0
|
|
4
|
+
|
|
5
|
+
- Rename `add_status!` to `assign_status!` to better reflect its purpose of assigning status information to headers or trailers.
|
|
6
|
+
|
|
3
7
|
## v0.5.0
|
|
4
8
|
|
|
5
9
|
- Server-side errors now automatically include backtraces in response headers when an error object is provided. Backtraces are transmitted as arrays via Split headers and can be extracted by clients.
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|