From 028cf7e606d7935d2a4fe9103cc5deecc9e4706c Mon Sep 17 00:00:00 2001 From: carolinacass <67160898+carolinacass@users.noreply.github.com> Date: Wed, 31 Aug 2022 13:37:08 +0100 Subject: [PATCH] HTTPResponseStatus should print code and reason (#2257) * HTTPResponseStatus should print code and reason * Update HTTPResponseStatusTests+XCTest.swift Co-authored-by: Carolina Cassedy Co-authored-by: Cory Benfield --- Sources/NIOHTTP1/HTTPTypes.swift | 6 ++++++ Tests/NIOHTTP1Tests/HTTPResponseStatusTests+XCTest.swift | 3 ++- Tests/NIOHTTP1Tests/HTTPResponseStatusTests.swift | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/NIOHTTP1/HTTPTypes.swift b/Sources/NIOHTTP1/HTTPTypes.swift index 16dbfb5d..2c3f139c 100644 --- a/Sources/NIOHTTP1/HTTPTypes.swift +++ b/Sources/NIOHTTP1/HTTPTypes.swift @@ -1311,6 +1311,12 @@ extension HTTPRequestHead: CustomStringConvertible { } } +extension HTTPResponseStatus: CustomStringConvertible { + public var description: String { + return "\(self.code) \(self.reasonPhrase)" + } +} + extension HTTPResponseHead: CustomStringConvertible { public var description: String { return "HTTPResponseHead { version: \(self.version), status: \(self.status), headers: \(self.headers) }" diff --git a/Tests/NIOHTTP1Tests/HTTPResponseStatusTests+XCTest.swift b/Tests/NIOHTTP1Tests/HTTPResponseStatusTests+XCTest.swift index 560c2f61..98e634b8 100644 --- a/Tests/NIOHTTP1Tests/HTTPResponseStatusTests+XCTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPResponseStatusTests+XCTest.swift @@ -2,7 +2,7 @@ // // This source file is part of the SwiftNIO open source project // -// Copyright (c) 2017-2021 Apple Inc. and the SwiftNIO project authors +// Copyright (c) 2017-2022 Apple Inc. and the SwiftNIO project authors // Licensed under Apache License v2.0 // // See LICENSE.txt for license information @@ -28,6 +28,7 @@ extension HTTPResponseStatusTests { static var allTests : [(String, (HTTPResponseStatusTests) -> () throws -> Void)] { return [ ("testHTTPResponseStatusFromStatusCode", testHTTPResponseStatusFromStatusCode), + ("testHTTPResponseStatusCodeAndReason", testHTTPResponseStatusCodeAndReason), ] } } diff --git a/Tests/NIOHTTP1Tests/HTTPResponseStatusTests.swift b/Tests/NIOHTTP1Tests/HTTPResponseStatusTests.swift index fbef9b80..00e3b49a 100644 --- a/Tests/NIOHTTP1Tests/HTTPResponseStatusTests.swift +++ b/Tests/NIOHTTP1Tests/HTTPResponseStatusTests.swift @@ -81,4 +81,10 @@ class HTTPResponseStatusTests: XCTestCase { XCTAssertEqual(HTTPResponseStatus(statusCode: 510), .notExtended) XCTAssertEqual(HTTPResponseStatus(statusCode: 511), .networkAuthenticationRequired) } + + func testHTTPResponseStatusCodeAndReason() { + XCTAssertEqual("\(HTTPResponseStatus.ok)", "200 OK") + XCTAssertEqual("\(HTTPResponseStatus.imATeapot)", "418 I'm a teapot") + XCTAssertEqual("\(HTTPResponseStatus.custom(code: 347, reasonPhrase: "I like ice cream"))", "347 I like ice cream") + } }