@@ -15,18 +15,21 @@ public import HTTPTypes
1515public import AsyncStreaming
1616
1717@available ( macOS 26 . 0 , iOS 26 . 0 , watchOS 26 . 0 , tvOS 26 . 0 , visionOS 26 . 0 , * )
18- /// A generic HTTP server protocol that can handle incoming HTTP requests.
19- public protocol HTTPServerProtocol : Sendable , ~ Copyable, ~ Escapable {
18+ /// A protocol that defines the interface for an HTTP server.
19+ ///
20+ /// ``HTTPServer`` provides the contract for server implementations that accept incoming HTTP connections and process requests
21+ /// using an ``HTTPServerRequestHandler``.
22+ public protocol HTTPServer : Sendable , ~ Copyable, ~ Escapable {
2023 /// The ``ConcludingAsyncReader`` to use when reading requests. ``ConcludingAsyncReader/FinalElement``
21- /// must be an optional `HTTPFields`, and ``ConcludingAsyncReader/Underlying`` must use `Span< UInt8> ` as its
24+ /// must be an optional `HTTPFields`, and ``ConcludingAsyncReader/Underlying`` must use `UInt8` as its
2225 /// `ReadElement`.
2326 associatedtype RequestReader : ConcludingAsyncReader & ~ Copyable & SendableMetatype
2427 where RequestReader. Underlying. ReadElement == UInt8 ,
2528 RequestReader. Underlying. ReadFailure == any Error ,
2629 RequestReader. FinalElement == HTTPFields ?
2730
2831 /// The ``ConcludingAsyncWriter`` to use when writing responses. ``ConcludingAsyncWriter/FinalElement``
29- /// must be an optional `HTTPFields`, and ``ConcludingAsyncWriter/Underlying`` must use `Span< UInt8> ` as its
32+ /// must be an optional `HTTPFields`, and ``ConcludingAsyncWriter/Underlying`` must use `UInt8` as its
3033 /// `WriteElement`.
3134 associatedtype ResponseWriter : ConcludingAsyncWriter & ~ Copyable & SendableMetatype
3235 where ResponseWriter. Underlying. WriteElement == UInt8 ,
@@ -47,22 +50,8 @@ public protocol HTTPServerProtocol: Sendable, ~Copyable, ~Escapable {
4750 /// ## Example
4851 ///
4952 /// ```swift
50- /// struct EchoHandler: HTTPServerRequestHandler {
51- /// func handle(
52- /// request: HTTPRequest,
53- /// requestContext: HTTPRequestContext,
54- /// requestBodyAndTrailers: consuming sending HTTPRequestConcludingAsyncReader,
55- /// responseSender: consuming sending HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
56- /// ) async throws {
57- /// let response = HTTPResponse(status: .ok)
58- /// let writer = try await responseSender.send(response)
59- /// // Handle request and write response...
60- /// }
61- /// }
62- ///
63- /// let server = // create an instance of a type conforming to the `ServerProtocol`
64- ///
65- /// try await server.serve(handler: EchoHandler())
53+ /// let server = // create an instance of a type conforming to the `HTTPServer` protocol
54+ /// try await server.serve(handler: YourRequestHandler())
6655 /// ```
6756 func serve( handler: some HTTPServerRequestHandler < RequestReader , ResponseWriter > ) async throws
6857}
0 commit comments