This PR contains the work done to do a little bit of housekeeping pass across all packages and the Website service. To provide further details about the work: * Refreshed the READMEs and source documentation to match the current code; * Tagged every test case consistently across the Infrastructure, Localization, Persistence, and Website test targets; * Removed Website middleware tests now covered by Infrastructure's own suite; * Conformed the `PrepareDB` method to Sendable; * Relaxes the production Compose DATABASE_TLS default from require to prefer; * Added Persistence test verifying the prefer posture falls back to plaintext connections. Reviewed-on: rock-n-code/loud-amsterdam#27 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
39 lines
1.2 KiB
Swift
39 lines
1.2 KiB
Swift
import Hummingbird
|
|
import Infrastructure
|
|
import NIOCore
|
|
|
|
/// The website's request context.
|
|
///
|
|
/// Extends the core request storage with the negotiated language, defaulting to the default supported language until ``LocalizationMiddleware``
|
|
/// resolves it from the request, and with the connected client's address, so ``RateLimitMiddleware`` can key its budgets per client.
|
|
public struct WebsiteRequestContext: LocalizedRequestContext, RemoteAddressRequestContext {
|
|
|
|
// MARK: Properties
|
|
|
|
/// The core request context storage Hummingbird requires.
|
|
public var coreContext: CoreRequestContextStorage
|
|
/// The language identifier negotiated for the request.
|
|
public var language: String
|
|
/// 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.language = .empty
|
|
self.remoteAddress = source.channel.remoteAddress
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Constants
|
|
|
|
private extension String {
|
|
static let empty = ""
|
|
}
|