Skip to content

Commit b30b5ed

Browse files
authored
Clarify what the RequestContext is for (#576)
* Clarify what the Requestcontext is for * Reduce line length
1 parent 56336d7 commit b30b5ed

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sources/Hummingbird/Server/RequestContext.swift

+13-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,19 @@ public struct CoreRequestContextStorage: Sendable {
5454
}
5555
}
5656

57-
/// Protocol that all request contexts should conform to. Holds data associated with
58-
/// a request. Provides context for request processing
57+
/// Protocol that all request contexts should conform to. A RequestContext is a statically typed metadata container for information
58+
/// that is associated with a ``Request``, and is therefore instantiated alongside the request.
59+
///
60+
/// It's passed along the whole middleware chain through to the route. This allows middleware and the route to share this metadata.
61+
///
62+
/// Typical use of a context includes:
63+
/// - The origin that sent the request (IP address or otherwise)
64+
/// - The identity, such as a user, that is associated with this request
65+
///
66+
/// The context is a statically typed metadata container for the duration of a single request.
67+
/// It's used to store values between middleware and routes such as the user's identity.
68+
///
69+
/// The lifetime of a RequestContext should not exceed that of the request.
5970
public protocol RequestContext: InitializableFromSource, RequestContextSource {
6071
associatedtype Source: RequestContextSource = ApplicationRequestContextSource
6172
associatedtype Decoder: RequestDecoder = JSONDecoder

0 commit comments

Comments
 (0)