From 57140e3abc697722a713b2fcb6345760cdee720b Mon Sep 17 00:00:00 2001 From: Tomohiro Kumagai Date: Fri, 14 Jul 2023 22:53:32 +0900 Subject: [PATCH] Make `Request.Method` and `Response.Status` conform to `Sendable`. --- Sources/HTTPTypes/HTTPRequest.swift | 2 +- Sources/HTTPTypes/HTTPResponse.swift | 2 +- Tests/HTTPTypesTests/HTTPTypesTests.swift | 27 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Sources/HTTPTypes/HTTPRequest.swift b/Sources/HTTPTypes/HTTPRequest.swift index 3904fda..0c33c48 100644 --- a/Sources/HTTPTypes/HTTPRequest.swift +++ b/Sources/HTTPTypes/HTTPRequest.swift @@ -22,7 +22,7 @@ /// the "Host" header. public struct HTTPRequest: Sendable, Hashable { /// The HTTP request method - public struct Method: Hashable, RawRepresentable, LosslessStringConvertible { + public struct Method: Sendable, Hashable, RawRepresentable, LosslessStringConvertible { /// The string value of the request. public let rawValue: String diff --git a/Sources/HTTPTypes/HTTPResponse.swift b/Sources/HTTPTypes/HTTPResponse.swift index 13e51d2..c0ac2f3 100644 --- a/Sources/HTTPTypes/HTTPResponse.swift +++ b/Sources/HTTPTypes/HTTPResponse.swift @@ -18,7 +18,7 @@ public struct HTTPResponse: Sendable, Hashable { /// The response status consisting of a 3-digit status code and a reason phrase. The reason /// phrase is ignored by modern HTTP versions. - public struct Status: Hashable, ExpressibleByIntegerLiteral, CustomStringConvertible { + public struct Status: Sendable, Hashable, ExpressibleByIntegerLiteral, CustomStringConvertible { /// The 3-digit status code. public let code: Int /// The reason phrase. diff --git a/Tests/HTTPTypesTests/HTTPTypesTests.swift b/Tests/HTTPTypesTests/HTTPTypesTests.swift index 8ac9503..05caffa 100644 --- a/Tests/HTTPTypesTests/HTTPTypesTests.swift +++ b/Tests/HTTPTypesTests/HTTPTypesTests.swift @@ -72,4 +72,31 @@ final class HTTPTypesTests: XCTestCase { XCTAssertEqual(response2.headerFields.count, 3) XCTAssertEqual(response2.headerFields[.server], "HTTPServer/1.0") } + + func testSendable() { + func isSendable(_ value: some Sendable) -> Bool { true } + func isSendable(_ value: Any) -> Bool { false } + + let field: HTTPField = HTTPField(name: .userAgent, value: "") + let indexingStrategy: HTTPField.DynamicTableIndexingStrategy = field.indexingStrategy + let name: HTTPField.Name = field.name + let fields: HTTPFields = [:] + let request: HTTPRequest = HTTPRequest(method: .post, scheme: nil, authority: nil, path: nil) + let method: HTTPRequest.Method = request.method + let requestPseudoHeaderFields: HTTPRequest.PseudoHeaderFields = request.pseudoHeaderFields + let response: HTTPResponse = HTTPResponse(status: .ok) + let status: HTTPResponse.Status = response.status + let responsePseudoHeaderFields: HTTPResponse.PseudoHeaderFields = response.pseudoHeaderFields + + XCTAssertTrue(isSendable(field)) + XCTAssertTrue(isSendable(indexingStrategy)) + XCTAssertTrue(isSendable(name)) + XCTAssertTrue(isSendable(fields)) + XCTAssertTrue(isSendable(request)) + XCTAssertTrue(isSendable(method)) + XCTAssertTrue(isSendable(requestPseudoHeaderFields)) + XCTAssertTrue(isSendable(response)) + XCTAssertTrue(isSendable(status)) + XCTAssertTrue(isSendable(responsePseudoHeaderFields)) + } }