Skip to content

Commit

Permalink
Max body size
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Ignition committed Jun 23, 2020
1 parent 312bd24 commit b5acc5a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Sources/CatbirdApp/AppConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public struct AppConfiguration {

/// The directory for mocks.
public let mocksDirectory: URL

public let maxBodySize: String
}

extension AppConfiguration {
Expand All @@ -36,9 +38,11 @@ extension AppConfiguration {
return url
}()

let maxBodySize = enviroment["CATBIRD_MAX_BODY_SIZE", default: "50mb"]

if let path = enviroment["CATBIRD_PROXY_URL"], let url = URL(string: path) {
return AppConfiguration(mode: .write(url), mocksDirectory: mocksDirectory)
return AppConfiguration(mode: .write(url), mocksDirectory: mocksDirectory, maxBodySize: maxBodySize)
}
return AppConfiguration(mode: .read, mocksDirectory: mocksDirectory)
return AppConfiguration(mode: .read, mocksDirectory: mocksDirectory, maxBodySize: maxBodySize)
}
}
1 change: 1 addition & 0 deletions Sources/CatbirdApp/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public struct CatbirdInfo: Content {
}

public func configure(_ app: Application, _ configuration: AppConfiguration) throws {
app.routes.defaultMaxBodySize = ByteCount(stringLiteral: configuration.maxBodySize)
let info = CatbirdInfo.current

// MARK: - Stores
Expand Down
5 changes: 4 additions & 1 deletion Tests/CatbirdAppTests/App/AppConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ final class AppConfigurationTests: XCTestCase {
let config = try AppConfiguration.detect(from: [:])
XCTAssertEqual(config.mode, .read)
XCTAssertEqual(config.mocksDirectory.absoluteString, AppConfiguration.sourceDir)
XCTAssertEqual(config.maxBodySize, "50mb")
}

func testDetectWriteMode() throws {
let config = try AppConfiguration.detect(from: [
"CATBIRD_PROXY_URL": "/"
"CATBIRD_PROXY_URL": "/",
"CATBIRD_MAX_BODY_SIZE": "1kb"
])
XCTAssertEqual(config.mode, .write(URL(string: "/")!))
XCTAssertEqual(config.mocksDirectory.absoluteString, AppConfiguration.sourceDir)
XCTAssertEqual(config.maxBodySize, "1kb")
}

}
6 changes: 5 additions & 1 deletion Tests/CatbirdAppTests/App/AppTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ class AppTestCase: XCTestCase {
}

func setUpApp(mode: AppConfiguration.Mode) throws {
let config = AppConfiguration(mode: mode, mocksDirectory: URL(string: mocksDirectory)!)
let config = AppConfiguration(
mode: mode,
mocksDirectory: URL(string: mocksDirectory)!,
maxBodySize: "50kb")
app = Application(.testing)
try configure(app, config)
}

override func setUp() {
super.setUp()
XCTAssertNoThrow(try setUpApp(mode: .read))
XCTAssertEqual(app.routes.defaultMaxBodySize, 51200)
}

override func tearDown() {
Expand Down

0 comments on commit b5acc5a

Please sign in to comment.