diff --git a/Sources/OpenAPIRuntime/Interface/HTTPBody.swift b/Sources/OpenAPIRuntime/Interface/HTTPBody.swift index c050450e..cb7e53f1 100644 --- a/Sources/OpenAPIRuntime/Interface/HTTPBody.swift +++ b/Sources/OpenAPIRuntime/Interface/HTTPBody.swift @@ -142,7 +142,7 @@ public final class HTTPBody: @unchecked Sendable { public let iterationBehavior: IterationBehavior /// Describes the total length of the body, if known. - public enum Length: Sendable { + public enum Length: Sendable, Equatable { /// Total length not known yet. case unknown @@ -542,10 +542,7 @@ extension HTTPBody { @inlinable public convenience init( _ string: some StringProtocol & Sendable ) { - self.init( - ByteChunk(string), - length: .known(string.count) - ) + self.init(ByteChunk(string)) } /// Creates a new body with the provided async throwing stream of strings. diff --git a/Tests/OpenAPIRuntimeTests/Interface/Test_HTTPBody.swift b/Tests/OpenAPIRuntimeTests/Interface/Test_HTTPBody.swift index 83fbe182..ae7b97d3 100644 --- a/Tests/OpenAPIRuntimeTests/Interface/Test_HTTPBody.swift +++ b/Tests/OpenAPIRuntimeTests/Interface/Test_HTTPBody.swift @@ -185,6 +185,13 @@ final class Test_Body: Test_Runtime { XCTAssertEqual(chunks, ["hel", "lo"].map { Array($0.utf8)[...] }) } + func testUTF8String() async throws { + XCTAssertEqual(HTTPBody("abc").length, .known(3)) + XCTAssertEqual(HTTPBody("🤘").length, .known(4)) + XCTAssertEqual(HTTPBody("\u{1f603}").length, .known(4)) + XCTAssertEqual(HTTPBody("árvíztűrő tükörfúrógép").length, .known(31)) + } + func testIterationBehavior_single() async throws { let sequence = AsyncStream( String.self,