diff --git a/Sources/Hummingbird/Files/FileMiddleware.swift b/Sources/Hummingbird/Files/FileMiddleware.swift index 0a7bcb69b..7f9a8d1b5 100644 --- a/Sources/Hummingbird/Files/FileMiddleware.swift +++ b/Sources/Hummingbird/Files/FileMiddleware.swift @@ -42,8 +42,6 @@ public protocol FileMiddlewareFileAttributes { /// "modified-date", "eTag", "content-type", "cache-control" and "content-range" headers where /// they are relevant. public struct FileMiddleware: RouterMiddleware where Provider.FileAttributes: FileMiddlewareFileAttributes { - struct IsDirectoryError: Error {} - let cacheControl: CacheControl let searchForIndexHtml: Bool let fileProvider: Provider @@ -152,7 +150,7 @@ extension FileMiddleware { // if file is a directory seach and `searchForIndexHtml` is set to true // then search for index.html in directory if attributes.isFolder { - guard self.searchForIndexHtml else { throw IsDirectoryError() } + guard self.searchForIndexHtml else { throw HTTPError(.notFound) } let indexPath = self.appendingPathComponent(path, "index.html") guard let indexAttributes = try await self.fileProvider.getAttributes(path: indexPath) else { throw HTTPError(.notFound) diff --git a/Tests/HummingbirdTests/FileMiddlewareTests.swift b/Tests/HummingbirdTests/FileMiddlewareTests.swift index 8c62b37f7..fc95e614e 100644 --- a/Tests/HummingbirdTests/FileMiddlewareTests.swift +++ b/Tests/HummingbirdTests/FileMiddlewareTests.swift @@ -316,6 +316,18 @@ class FileMiddlewareTests: XCTestCase { } } + func testFolder() async throws { + let router = Router() + router.middlewares.add(FileMiddleware(".", searchForIndexHtml: false)) + let app = Application(responder: router.buildResponder()) + + try await app.test(.router) { client in + try await client.execute(uri: "/", method: .get) { response in + XCTAssertEqual(response.status, .notFound) + } + } + } + func testCustomFileProvider() async throws { // basic file provider struct MemoryFileProvider: FileProvider {