Skip to content

Commit 497dc47

Browse files
committed
Add typealias AWSMiddlewareNextHandler (#580)
1 parent b3f7832 commit 497dc47

10 files changed

+18
-16
lines changed

Sources/SotoCore/Middleware/Middleware.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ public struct AWSMiddlewareContext {
2121
public var logger: Logger
2222
}
2323

24+
/// Function to call next middleware in the chain
25+
public typealias AWSMiddlewareNextHandler = (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse
2426
/// Middleware handler, function that takes a request, context and the next function to call
25-
public typealias AWSMiddlewareHandler = @Sendable (AWSHTTPRequest, AWSMiddlewareContext, _ next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse
27+
public typealias AWSMiddlewareHandler = @Sendable (AWSHTTPRequest, AWSMiddlewareContext, _ next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse
2628

2729
/// Middleware protocol, with function that takes a request, context and the next function to call
2830
public protocol AWSMiddlewareProtocol: Sendable {
29-
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse
31+
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse
3032
}
3133

3234
/// Middleware initialized with a middleware handle
@@ -39,7 +41,7 @@ public struct AWSMiddleware: AWSMiddlewareProtocol {
3941
}
4042

4143
@inlinable
42-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
44+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
4345
try await self.middleware(request, context, next)
4446
}
4547
}
@@ -56,7 +58,7 @@ public struct AWSMiddleware2<M0: AWSMiddlewareProtocol, M1: AWSMiddlewareProtoco
5658
}
5759

5860
@inlinable
59-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
61+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
6062
try await self.m0.handle(request, context: context) { request, context in
6163
try await self.m1.handle(request, context: context, next: next)
6264
}
@@ -80,7 +82,7 @@ public struct AWSDynamicMiddlewareStack: AWSMiddlewareProtocol {
8082
}
8183

8284
@inlinable
83-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
85+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
8486
let iterator = self.stack.makeIterator()
8587
return try await self.run(request, context: context, iterator: iterator, finally: next)
8688
}
@@ -90,7 +92,7 @@ public struct AWSDynamicMiddlewareStack: AWSMiddlewareProtocol {
9092
_ request: AWSHTTPRequest,
9193
context: AWSMiddlewareContext,
9294
iterator: Stack.Iterator,
93-
finally: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse
95+
finally: AWSMiddlewareNextHandler
9496
) async throws -> AWSHTTPResponse {
9597
var iterator = iterator
9698
switch iterator.next() {
@@ -107,7 +109,7 @@ public struct AWSDynamicMiddlewareStack: AWSMiddlewareProtocol {
107109
public struct PassThruMiddleware: AWSMiddlewareProtocol {
108110
public init() {}
109111

110-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
112+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
111113
try await next(request, context)
112114
}
113115
}

Sources/SotoCore/Middleware/Middleware/EditHeadersMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct AWSEditHeadersMiddleware: AWSMiddlewareProtocol {
3434
}
3535

3636
@inlinable
37-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
37+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
3838
var request = request
3939
for edit in self.edits {
4040
switch edit {

Sources/SotoCore/Middleware/Middleware/EndpointDiscoveryMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public struct EndpointDiscoveryMiddleware: AWSMiddlewareProtocol {
3737
self.isRequired = required
3838
}
3939

40-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
40+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
4141
let isEnabled = context.serviceConfig.options.contains(.enableEndpointDiscovery)
4242
guard isEnabled || self.isRequired else {
4343
return try await next(request, context)

Sources/SotoCore/Middleware/Middleware/ErrorHandlingMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SotoSignerV4
2020
struct ErrorHandlingMiddleware: AWSMiddlewareProtocol {
2121
let options: AWSClient.Options
2222

23-
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
23+
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
2424
let response = try await next(request, context)
2525

2626
// if response has an HTTP status code outside 2xx then throw an error

Sources/SotoCore/Middleware/Middleware/LoggingMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public struct AWSLoggingMiddleware: AWSMiddlewareProtocol {
3838
}
3939

4040
@inlinable
41-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
41+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
4242
self.log(
4343
"Request:\n" +
4444
" \(context.operation)\n" +

Sources/SotoCore/Middleware/Middleware/RetryMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct RetryMiddleware: AWSMiddlewareProtocol {
2222
let retryPolicy: RetryPolicy
2323

2424
@inlinable
25-
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
25+
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
2626
var attempt = 0
2727
while true {
2828
do {

Sources/SotoCore/Middleware/Middleware/S3Middleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Foundation
3030
/// - Fixes up the GetBucketLocation response, so it can be decoded correctly
3131
/// - Creates error body for notFound responses to HEAD requests
3232
public struct S3Middleware: AWSMiddlewareProtocol {
33-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
33+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
3434
var request = request
3535

3636
self.virtualAddressFixup(request: &request, context: context)

Sources/SotoCore/Middleware/Middleware/SigningMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct SigningMiddleware: AWSMiddlewareProtocol {
2222
let credentialProvider: any CredentialProvider
2323

2424
@inlinable
25-
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
25+
func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
2626
var request = request
2727
// get credentials
2828
let credential = try await self.credentialProvider.getCredential(logger: context.logger)

Sources/SotoCore/Middleware/Middleware/TracingMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public struct AWSTracingMiddleware: AWSMiddlewareProtocol {
2424
public func handle(
2525
_ request: AWSHTTPRequest,
2626
context: AWSMiddlewareContext,
27-
next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse
27+
next: AWSMiddlewareNextHandler
2828
) async throws -> AWSHTTPResponse {
2929
try await InstrumentationSystem.tracer.withSpan(
3030
"\(context.serviceConfig.serviceName).\(context.operation)",

Sources/SotoCore/Middleware/Middleware/TreeHashMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let MEGA_BYTE = 1024 * 1024
2121
/// Calculates a tree hash calculated from the SHA256 of each 1MB section of the request body
2222
/// and adds it to the request as a header value
2323
public struct TreeHashMiddleware: AWSMiddlewareProtocol {
24-
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: (AWSHTTPRequest, AWSMiddlewareContext) async throws -> AWSHTTPResponse) async throws -> AWSHTTPResponse {
24+
public func handle(_ request: AWSHTTPRequest, context: AWSMiddlewareContext, next: AWSMiddlewareNextHandler) async throws -> AWSHTTPResponse {
2525
var request = request
2626
if request.headers[self.treeHashHeader].first == nil {
2727
if case .byteBuffer(let buffer) = request.body.storage {

0 commit comments

Comments
 (0)