Skip to content

Commit 0d850d6

Browse files
jtdaveyglbrntt
andauthored
Add a new field, transportSpecific to ServerContext (#2228)
Motivation: Currently there's no way to plumb through details from the transport level to a request handler. Adding this field allows transports, such as the nio transport, to add the peer certificate to the server context when using mTLS. From there there it's easy for an interceptor to take this data and propogate it forward to a request handler. Modifications: This PR adds a single field to the ServerContext that transports can use Result: A new field will be accessible to transports and consumers of the API --------- Co-authored-by: George Barnett <[email protected]>
1 parent d8185e7 commit 0d850d6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sources/GRPCCore/Call/Server/ServerContext.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
/// Additional information about an RPC handled by a server.
1818
public struct ServerContext: Sendable {
19+
20+
/// Protocol used to help identify transport specific context fields
21+
public protocol TransportSpecific: Sendable {}
22+
1923
/// A description of the method being called.
2024
public var descriptor: MethodDescriptor
2125

@@ -45,6 +49,15 @@ public struct ServerContext: Sendable {
4549
/// - "in-process:27182".
4650
public var localPeer: String
4751

52+
/// An optional field for transports to store specific data
53+
///
54+
/// Refer to the transport documentation to understand what type of
55+
/// value this field will contain, if any.
56+
///
57+
/// An example of what this field can be used for, would be to store
58+
/// things like a peer certificate from a mTLS connection
59+
public var transportSpecific: (any TransportSpecific)?
60+
4861
/// A handle for checking the cancellation status of an RPC.
4962
public var cancellation: RPCCancellationHandle
5063

0 commit comments

Comments
 (0)