Skip to content

Commit 300dbd1

Browse files
authored
RouterMethods.add(middlewareStack:) -> RouterMethods.addMiddleware(mi… (#540)
* RouterMethods.add(middlewareStack:) -> RouterMethods.addMiddleware(middlewareStack:) * Rename parameter, minor formatting change * formatting
1 parent ce76c21 commit 300dbd1

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Sources/Hummingbird/Configuration.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public struct ApplicationConfiguration: Sendable {
4848
/// - Parameters:
4949
/// - address: Bind address for server
5050
/// - serverName: Server name to return in "server" header
51-
/// - backlog: the maximum length for the queue of pending connections. If a connection request
51+
/// - backlog: the maximum length for the queue of pending connections. If a connection request
5252
/// arrives with the queue full, the client may receive an error with an indication of ECONNREFUSE
5353
/// - reuseAddress: Allows socket to be bound to an address that is already in use.
54-
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
54+
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
5555
/// ``HummingbirdCore/MaximumAvailableConnections`` to set the maximum allowed connections.
5656
public init(
5757
address: BindAddress = .hostname(),
@@ -77,7 +77,7 @@ public struct ApplicationConfiguration: Sendable {
7777
/// - address: Bind address for server
7878
/// - serverName: Server name to return in "server" header
7979
/// - reuseAddress: Allows socket to be bound to an address that is already in use.
80-
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
80+
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
8181
/// ``HummingbirdCore/MaximumAvailableConnections`` to set the maximum allowed connections.
8282
/// - tlsOptions: TLS options for when you are using NIOTransportServices
8383
public init(

Sources/Hummingbird/Router/RouterMethods.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extension RouterMethods {
8989
/// ``MiddlewareFixedTypeBuilder``.
9090
///
9191
/// ```swift
92-
/// router.add {
92+
/// router.addMiddleware {
9393
/// LogRequestsMiddleware()
9494
/// MetricsMiddleware()
9595
/// }
@@ -98,10 +98,10 @@ extension RouterMethods {
9898
///
9999
/// - Parameter middlewareStack: Middleware stack result builder
100100
/// - Returns: router
101-
@discardableResult public func add(
102-
@MiddlewareFixedTypeBuilder<Request, Response, Context> middlewareStack: () -> some MiddlewareProtocol<Request, Response, Context>
101+
@discardableResult public func addMiddleware(
102+
@MiddlewareFixedTypeBuilder<Request, Response, Context> buildMiddlewareStack: () -> some MiddlewareProtocol<Request, Response, Context>
103103
) -> Self {
104-
return self.add(middleware: middlewareStack())
104+
return self.add(middleware: buildMiddlewareStack())
105105
}
106106

107107
/// GET path for async closure returning type conforming to ResponseGenerator

Sources/HummingbirdCore/Response/ResponseBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public struct ResponseBody: Sendable {
6262
/// Initialise ResponseBody that contains a sequence of ByteBuffers
6363
/// - Parameter byteBuffers: Sequence of ByteBuffers to write
6464
public init<BufferSequence: Sequence & Sendable>(contentsOf byteBuffers: BufferSequence) where BufferSequence.Element == ByteBuffer {
65-
self.init(contentLength: byteBuffers.map { $0.readableBytes }.reduce(0, +)) { writer in
65+
self.init(contentLength: byteBuffers.map(\.readableBytes).reduce(0, +)) { writer in
6666
try await writer.write(contentsOf: byteBuffers)
6767
try await writer.finish(nil)
6868
}

Tests/HummingbirdTests/MiddlewareTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ final class MiddlewareTests: XCTestCase {
461461
}
462462
}
463463
let router = Router()
464-
router.add {
464+
router.addMiddleware {
465465
TestMiddleware(string: "first")
466466
TestMiddleware(string: "second")
467467
}

0 commit comments

Comments
 (0)