HTTPResponseStatus should print code and reason (#2257)

* HTTPResponseStatus should print code and reason

* Update HTTPResponseStatusTests+XCTest.swift

Co-authored-by: Carolina Cassedy <ccassedy@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
carolinacass 2022-08-31 13:37:08 +01:00 committed by GitHub
parent 2c453d6e49
commit 028cf7e606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -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) }"

View File

@ -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),
]
}
}

View File

@ -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")
}
}