Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collected request body drain .end #2222

Merged
merged 1 commit into from Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/Vapor/Request/Request+Body.swift
Expand Up @@ -29,6 +29,7 @@ extension Request {
}
case .collected(let buffer):
_ = handler(.buffer(buffer))
_ = handler(.end)
case .none: break
}
}
Expand Down
47 changes: 47 additions & 0 deletions Tests/VaporTests/ApplicationTests.swift
Expand Up @@ -1439,7 +1439,54 @@ final class ApplicationTests: XCTestCase {
let data = Data([1, 2, 3, 4])
XCTAssertEqual(data.base32EncodedString(), "AEBAGBA")
XCTAssertEqual(Data(base32Encoded: "AEBAGBA"), data)
}

func testSimilarRoutingPath() throws {
let app = Application(.testing)
defer { app.shutdown() }

app.get("api","addresses") { req in
"a"
}
app.get("api", "addresses","search", ":id") { req in
"b"
}

try app.testable(method: .running).test(.GET, "/api/addresses/") { res in
XCTAssertEqual(res.body.string, "a")
}.test(.GET, "/api/addresses/search/test") { res in
XCTAssertEqual(res.body.string, "b")
}.test(.GET, "/api/addresses/search/") { res in
XCTAssertEqual(res.status, .notFound)
}.test(.GET, "/api/addresses/search") { res in
XCTAssertEqual(res.status, .notFound)
}
}

func testCollectedResponseBodyEnd() throws {
let app = Application(.testing)
defer { app.shutdown() }

app.post("drain") { req -> EventLoopFuture<HTTPStatus> in
let promise = req.eventLoop.makePromise(of: HTTPStatus.self)
req.body.drain { result in
switch result {
case .buffer: break
case .error(let error):
promise.fail(error)
case .end:
promise.succeed(.ok)
}
return req.eventLoop.makeSucceededFuture(())
}
return promise.futureResult
}

try app.testable(method: .running).test(.POST, "drain", beforeRequest: { req in
try req.content.encode(["hello": "world"])
}, afterResponse: { res in
XCTAssertEqual(res.status, .ok)
})
}
}

Expand Down