Repository: vapor/vapor
File: Sources/Vapor/Response/ApplicationResponder.swift (Swift)

Code before:
/// Vapor's main `Responder` type. Combines configured middleware + router to create a responder.
public struct ApplicationResponder: Responder, ServiceType {
    /// See `ServiceType`.
    public static var serviceSupports: [Any.Type] { return [Responder.self] }

    /// See `ServiceType`.
    public static func makeService(for container: Container) throws -> ApplicationResponder {
        // initialize all `[Middleware]` from config
        let middleware = try container
            .make(MiddlewareConfig.self)
            .resolve(for: container)

        // create router and wrap in a responder
        let router = try container.make(Router.self)

        // return new responder
        return ApplicationResponder(router, middleware: middleware)
    }

    /// Wrapped `Responder`.
    private let responder: Responder

    /// Creates a new `ApplicationResponder`.
    public init(_ router: Router, middleware: [Middleware]) {
        let router = RouterResponder(router: router)
        let wrapped = middleware.makeResponder(chainedto: router)
        self.responder = wrapped
    }

    /// See `Responder`.
    public func respond(to req: Request) throws -> Future<Response> {
        return try responder.respond(to: req)
    }
}

// MARK: Private

/// Converts a `Router` into a `Responder`.
private struct RouterResponder: Responder {
    let router: Router

    /// Creates a new `RouterResponder`.
    init(router: Router) {
        self.router = router
    }

    /// See `Responder`.
    func respond(to req: Request) throws -> Future<Response> {
        guard let responder = router.route(request: req) else {

Review comment (suggestion):
Either both should have labels or both not I think. Also middleware can have a default arg to `[]`. 

Code after:
/// Vapor's main `Responder` type. Combines configured middleware + router to create a responder.
public struct ApplicationResponder: Responder, ServiceType {
    /// See `ServiceType`.
    public static var serviceSupports: [Any.Type] { return [Responder.self] }

    /// See `ServiceType`.
    public static func makeService(for container: Container) throws -> ApplicationResponder {
        // initialize all `[Middleware]` from config
        let middleware = try container
            .make(MiddlewareConfig.self)
            .resolve(for: container)

        // create router and wrap in a responder
        let router = try container.make(Router.self)

        // return new responder
        return ApplicationResponder(router, middleware)
    }

    /// Wrapped `Responder`.
    private let responder: Responder

    /// Creates a new `ApplicationResponder`.
    public init(_ router: Router, _ middleware: [Middleware] = []) {
        let router = RouterResponder(router: router)
        let wrapped = middleware.makeResponder(chainedto: router)
        self.responder = wrapped
    }

    /// See `Responder`.
    public func respond(to req: Request) throws -> Future<Response> {
        return try responder.respond(to: req)
    }
}

// MARK: Private

/// Converts a `Router` into a `Responder`.
private struct RouterResponder: Responder {
    let router: Router

    /// Creates a new `RouterResponder`.
    init(router: Router) {
        self.router = router
    }

    /// See `Responder`.
    func respond(to req: Request) throws -> Future<Response> {
        guard let responder = router.route(request: req) else {