Skip to content

Commit

Permalink
RouterMethods.add(middlewareStack:) -> RouterMethods.addMiddleware(mi… (
Browse files Browse the repository at this point in the history
#540)

* RouterMethods.add(middlewareStack:) -> RouterMethods.addMiddleware(middlewareStack:)

* Rename parameter, minor formatting change

* formatting
  • Loading branch information
adam-fowler authored Sep 7, 2024
1 parent ce76c21 commit 300dbd1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Sources/Hummingbird/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public struct ApplicationConfiguration: Sendable {
/// - Parameters:
/// - address: Bind address for server
/// - serverName: Server name to return in "server" header
/// - backlog: the maximum length for the queue of pending connections. If a connection request
/// - backlog: the maximum length for the queue of pending connections. If a connection request
/// arrives with the queue full, the client may receive an error with an indication of ECONNREFUSE
/// - reuseAddress: Allows socket to be bound to an address that is already in use.
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
/// ``HummingbirdCore/MaximumAvailableConnections`` to set the maximum allowed connections.
public init(
address: BindAddress = .hostname(),
Expand All @@ -77,7 +77,7 @@ public struct ApplicationConfiguration: Sendable {
/// - address: Bind address for server
/// - serverName: Server name to return in "server" header
/// - reuseAddress: Allows socket to be bound to an address that is already in use.
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
/// - availableConnectionsDelegate: Object deciding on when we should accept new connection. Use
/// ``HummingbirdCore/MaximumAvailableConnections`` to set the maximum allowed connections.
/// - tlsOptions: TLS options for when you are using NIOTransportServices
public init(
Expand Down
8 changes: 4 additions & 4 deletions Sources/Hummingbird/Router/RouterMethods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extension RouterMethods {
/// ``MiddlewareFixedTypeBuilder``.
///
/// ```swift
/// router.add {
/// router.addMiddleware {
/// LogRequestsMiddleware()
/// MetricsMiddleware()
/// }
Expand All @@ -98,10 +98,10 @@ extension RouterMethods {
///
/// - Parameter middlewareStack: Middleware stack result builder
/// - Returns: router
@discardableResult public func add(
@MiddlewareFixedTypeBuilder<Request, Response, Context> middlewareStack: () -> some MiddlewareProtocol<Request, Response, Context>
@discardableResult public func addMiddleware(
@MiddlewareFixedTypeBuilder<Request, Response, Context> buildMiddlewareStack: () -> some MiddlewareProtocol<Request, Response, Context>
) -> Self {
return self.add(middleware: middlewareStack())
return self.add(middleware: buildMiddlewareStack())
}

/// GET path for async closure returning type conforming to ResponseGenerator
Expand Down
2 changes: 1 addition & 1 deletion Sources/HummingbirdCore/Response/ResponseBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct ResponseBody: Sendable {
/// Initialise ResponseBody that contains a sequence of ByteBuffers
/// - Parameter byteBuffers: Sequence of ByteBuffers to write
public init<BufferSequence: Sequence & Sendable>(contentsOf byteBuffers: BufferSequence) where BufferSequence.Element == ByteBuffer {
self.init(contentLength: byteBuffers.map { $0.readableBytes }.reduce(0, +)) { writer in
self.init(contentLength: byteBuffers.map(\.readableBytes).reduce(0, +)) { writer in
try await writer.write(contentsOf: byteBuffers)
try await writer.finish(nil)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/HummingbirdTests/MiddlewareTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ final class MiddlewareTests: XCTestCase {
}
}
let router = Router()
router.add {
router.addMiddleware {
TestMiddleware(string: "first")
TestMiddleware(string: "second")
}
Expand Down

0 comments on commit 300dbd1

Please sign in to comment.