Files

29 lines
884 B
Swift
Raw Permalink Normal View History

2026-08-19 22:55:00 +02:00
import Hummingbird
import Infrastructure
import NIOCore
/// The website's request context.
///
2026-09-20 12:45:58 +02:00
/// Extends the core request storage with the connected client's address, so ``RateLimitMiddleware`` can key its budgets per client.
public struct WebsiteRequestContext: RemoteAddressRequestContext {
2026-08-19 22:55:00 +02:00
// MARK: Properties
/// The core request context storage Hummingbird requires.
public var coreContext: CoreRequestContextStorage
/// The address of the connected client, captured from the source channel.
public let remoteAddress: SocketAddress?
// MARK: Initializers
/// Creates a request context for the given source.
/// - Parameter source: the source the context is initialized from.
public init(
source: Source,
) {
self.coreContext = .init(source: source)
self.remoteAddress = source.channel.remoteAddress
}
}