@@ -20,32 +20,38 @@ import NIOCore
20
20
struct TransformingRouterGroup < InputContext: RequestContext , Context: RequestContext > : RouterMethods {
21
21
typealias TransformContext = Context
22
22
let parent : any RouterMethods < InputContext >
23
- let transform : @Sendable ( Request, InputContext) async throws -> TransformContext
23
+ let transform : @Sendable ( Request , InputContext , ( Request , TransformContext ) async throws -> Response ) async throws -> Response
24
24
25
25
struct ContextTransformingResponder : HTTPResponder {
26
26
typealias Context = InputContext
27
27
let responder : any HTTPResponder < TransformContext >
28
- let transform : @Sendable ( Request, InputContext) async throws -> TransformContext
28
+ let transform : @Sendable (
29
+ Request ,
30
+ InputContext ,
31
+ ( Request , TransformContext ) async throws -> Response
32
+ ) async throws -> Response
29
33
30
34
func respond( to request: Request , context: InputContext ) async throws -> Response {
31
- let newContext = try await transform ( request, context)
32
- return try await self . responder. respond ( to: request, context: newContext)
35
+ try await transform ( request, context) { req, context in
36
+ try await self . responder. respond ( to: request, context: context)
37
+ }
33
38
}
34
39
}
35
40
36
41
init ( parent: any RouterMethods < InputContext > ) where Context. Source == InputContext {
37
42
self . parent = parent
38
- self . transform = { _, context in
39
- TransformContext ( source: context)
43
+ self . transform = { req, context, next in
44
+ let context = TransformContext ( source: context)
45
+ return try await next ( req, context)
40
46
}
41
47
}
42
48
43
49
init (
44
50
parent: any RouterMethods < InputContext > ,
45
- transform : @escaping @ Sendable ( Request, InputContext) async throws -> TransformContext
51
+ middleware : some ContextTransformingMiddlewareProtocol < Request , Response , InputContext , Context >
46
52
) {
47
53
self . parent = parent
48
- self . transform = transform
54
+ self . transform = middleware . handle
49
55
}
50
56
51
57
/// Add middleware (Stub function as it isn't used)
0 commit comments