Add asRaw to ParsedBody
MODIFY
Sources/Kitura/bodyParser/ParsedBody.swift
Sources/Kitura/bodyParser/ParsedBody.swift
@@ -69,6 +69,18 @@ public indirect enum ParsedBody {
}
}
+ /// Extract a "raw" body from the `ParsedBody` enum
+ ///
+ /// - Returns: The "raw" body as a Data, or nil if the body wasn't in raw format.
+ public var asRaw: Data? {
+ switch self {
+ case .raw(let body):
+ return body
+ default:
+ return nil
+ }
+ }
+
/// Extract a "text" body from the `ParsedBody` enum
///
/// - Returns: The "text" body as a String, or nil if the body wasn't in text format.

MODIFY
Tests/KituraTests/TestResponse.swift
Tests/KituraTests/TestResponse.swift
@@ -1221,7 +1221,7 @@ class TestResponse: KituraTest {
} catch {
XCTFail("caught error: \(error)")
}
- } else if case let .raw(data) = requestBody {
+ } else if let data = requestBody.asRaw {
XCTAssertNotNil(data)
let length = "2048"
_ = response.send("length: \(length)")

Add asRaw to ParsedBody (#1258)