diff --git a/Sources/NIOHTTP1/HTTPTypes.swift b/Sources/NIOHTTP1/HTTPTypes.swift index 321b494d6d..92579c9ec7 100644 --- a/Sources/NIOHTTP1/HTTPTypes.swift +++ b/Sources/NIOHTTP1/HTTPTypes.swift @@ -313,7 +313,10 @@ public struct HTTPHeaders: CustomStringConvertible, ExpressibleByDictionaryLiter internal var keepAliveState: KeepAliveState = .unknown public var description: String { - self.headers.description + self.headers.lazy.map { + "\($0.0): \($0.1)" + } + .joined(separator: "; ") } internal var names: [String] { diff --git a/Tests/NIOHTTP1Tests/HTTPHeadersTest.swift b/Tests/NIOHTTP1Tests/HTTPHeadersTest.swift index bd424f77dc..4971af97a8 100644 --- a/Tests/NIOHTTP1Tests/HTTPHeadersTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPHeadersTest.swift @@ -400,4 +400,26 @@ class HTTPHeadersTest: XCTestCase { headers.reserveCapacity(4) XCTAssertEqual(headers.capacity, 4) } + + func testHTTPHeadersDescription() { + let originalHeaders = [ + ("User-Agent", "1"), + ("host", "2"), + ("X-SOMETHING", "3"), + ("SET-COOKIE", "foo=bar"), + ("Set-Cookie", "buz=cux"), + ] + + let headers = HTTPHeaders(originalHeaders) + + let expectedOutput = """ + User-Agent: 1; \ + host: 2; \ + X-SOMETHING: 3; \ + SET-COOKIE: foo=bar; \ + Set-Cookie: buz=cux + """ + + XCTAssertEqual(expectedOutput, headers.description) + } }