Repository: apple/swift-nio
File: Sources/NIOHTTP1/HTTPTypes.swift (Swift)

Code before:
    public init(version: HTTPVersion, method: HTTPMethod, uri: String) {
        self.init(version: version, method: method, uri: uri, headers: HTTPHeaders())
    }

    public static func ==(lhs: HTTPRequestHead, rhs: HTTPRequestHead) -> Bool {
        return lhs.method == rhs.method && lhs.uri == rhs.uri && lhs.version == rhs.version && lhs.headers == rhs.headers
    }

    private mutating func copyStorageIfNotUniquelyReferenced () {
        if !isKnownUniquelyReferenced(&self._storage) {
            self._storage = self._storage.copy()
        }
    }
}

extension HTTPRequestHead: @unchecked Sendable {}

/// The parts of a complete HTTP message, representing either a request or a response.
/// 
/// An HTTP message is made up of:
/// - a request or status line with several headers, encoded by a single ``HTTPPart/head(_:)`` part,
/// - zero or more ``HTTPPart/body(_:)`` parts,
/// - and some optional trailers (represented as headers) in a single ``HTTPPart/end(_:)`` part.
/// 
/// To indicate that a complete HTTP message has been sent or received,
/// an ``HTTPPart/end(_:)`` part should always be used, even when no trailers are included.
public enum HTTPPart<HeadT: Equatable, BodyT: Equatable> {
    /// The headers of an HTTP request or response.
    ///
    /// A single part is always used to encode all headers.
    case head(HeadT)
    
    /// A part of an HTTP request or response's body.
    ///
    /// Zero or more body parts can be sent or received. The stream is finished when
    /// an ``HTTPPart/end(_:)`` part is received.
    case body(BodyT)
    
    /// The end of an HTTP request or response, optionally containing trailers.
    ///
    /// A single part is always used to encode all trailers.
    case end(HTTPHeaders?)
}

extension HTTPPart: Sendable where HeadT: Sendable, BodyT: Sendable {}

extension HTTPPart: Equatable {}

/// The components of a HTTP request from the view of a HTTP client.
public typealias HTTPClientRequestPart = HTTPPart<HTTPRequestHead, IOData>


Review comment (suggestion):
"should" is a suggestion, "must" is a requirement so let's use that here:

```suggestion
/// an ``HTTPPart/end(_:)`` part must be used, even when no trailers are included.
```

Code after:
    public init(version: HTTPVersion, method: HTTPMethod, uri: String) {
        self.init(version: version, method: method, uri: uri, headers: HTTPHeaders())
    }

    public static func ==(lhs: HTTPRequestHead, rhs: HTTPRequestHead) -> Bool {
        return lhs.method == rhs.method && lhs.uri == rhs.uri && lhs.version == rhs.version && lhs.headers == rhs.headers
    }

    private mutating func copyStorageIfNotUniquelyReferenced () {
        if !isKnownUniquelyReferenced(&self._storage) {
            self._storage = self._storage.copy()
        }
    }
}

extension HTTPRequestHead: @unchecked Sendable {}

/// The parts of a complete HTTP message, representing either a request or a response.
/// 
/// An HTTP message is made up of:
/// - a request or status line with several headers, encoded by a single ``HTTPPart/head(_:)`` part,
/// - zero or more ``HTTPPart/body(_:)`` parts,
/// - and some optional trailers (represented as headers) in a single ``HTTPPart/end(_:)`` part.
/// 
/// To indicate that a complete HTTP message has been sent or received,
/// an ``HTTPPart/end(_:)`` part must be used, even when no trailers are included.
public enum HTTPPart<HeadT: Equatable, BodyT: Equatable> {
    /// The headers of an HTTP request or response.
    ///
    /// A single part is always used to encode all headers.
    case head(HeadT)
    
    /// A part of an HTTP request or response's body.
    ///
    /// Zero or more body parts can be sent or received. The stream is finished when
    /// an ``HTTPPart/end(_:)`` part is received.
    case body(BodyT)
    
    /// The end of an HTTP request or response, optionally containing trailers.
    ///
    /// A single part is always used to encode all trailers.
    case end(HTTPHeaders?)
}

extension HTTPPart: Sendable where HeadT: Sendable, BodyT: Sendable {}

extension HTTPPart: Equatable {}

/// The components of a HTTP request from the view of a HTTP client.
public typealias HTTPClientRequestPart = HTTPPart<HTTPRequestHead, IOData>