Skip to content

Commit fb5cf19

Browse files
committed
Some renames + fix docs
1 parent d832ac3 commit fb5cf19

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

Sources/HTTPServer/HTTPServerClosureRequestHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ extension HTTPServerProtocol {
100100
/// }
101101
/// ```
102102
public func serve(
103-
body: @Sendable @escaping (
103+
handler: @Sendable @escaping (
104104
_ request: HTTPRequest,
105105
_ requestContext: HTTPRequestContext,
106106
_ requestBodyAndTrailers: consuming sending ConcludingRequestReader,
107107
_ responseSender: consuming sending HTTPResponseSender<ConcludingResponseWriter>
108108
) async throws -> Void
109109
) async throws {
110-
try await self.serve(handler: HTTPServerClosureRequestHandler(handler: body))
110+
try await self.serve(handler: HTTPServerClosureRequestHandler(handler: handler))
111111
}
112112
}

Sources/HTTPServer/HTTPServerProtocol.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ public protocol HTTPServerProtocol: Sendable, ~Copyable, ~Escapable {
66
/// The ``ConcludingAsyncReader`` to use when reading requests. ``ConcludingAsyncReader/FinalElement``
77
/// must be an optional `HTTPFields`, and ``ConcludingAsyncReader/Underlying`` must use `Span<UInt8>` as its
88
/// `ReadElement`.
9-
associatedtype ConcludingRequestReader: ConcludingAsyncReader & ~Copyable & SendableMetatype
10-
where ConcludingRequestReader.Underlying.ReadElement == Span<UInt8>,
11-
ConcludingRequestReader.Underlying.ReadFailure == any Error,
12-
ConcludingRequestReader.FinalElement == HTTPFields?
9+
associatedtype RequestReader: ConcludingAsyncReader & ~Copyable & SendableMetatype
10+
where RequestReader.Underlying.ReadElement == Span<UInt8>,
11+
RequestReader.Underlying.ReadFailure == any Error,
12+
RequestReader.FinalElement == HTTPFields?
1313

14-
/// The ``ConcludingAsyncWriter`` to use when reading requests. ``ConcludingAsyncWriter/FinalElement``
14+
/// The ``ConcludingAsyncWriter`` to use when writing responses. ``ConcludingAsyncWriter/FinalElement``
1515
/// must be an optional `HTTPFields`, and ``ConcludingAsyncWriter/Underlying`` must use `Span<UInt8>` as its
1616
/// `WriteElement`.
17-
associatedtype ConcludingResponseWriter: ConcludingAsyncWriter & ~Copyable & SendableMetatype
18-
where ConcludingResponseWriter.Underlying.WriteElement == Span<UInt8>,
19-
ConcludingResponseWriter.Underlying.WriteFailure == any Error,
20-
ConcludingResponseWriter.FinalElement == HTTPFields?
17+
associatedtype ResponseWriter: ConcludingAsyncWriter & ~Copyable & SendableMetatype
18+
where ResponseWriter.Underlying.WriteElement == Span<UInt8>,
19+
ResponseWriter.Underlying.WriteFailure == any Error,
20+
ResponseWriter.FinalElement == HTTPFields?
2121

2222
/// Starts an HTTP server with the specified request handler.
2323
///
@@ -28,16 +28,17 @@ public protocol HTTPServerProtocol: Sendable, ~Copyable, ~Escapable {
2828
///
2929
/// - Parameters:
3030
/// - handler: A ``HTTPServerRequestHandler`` implementation that processes incoming HTTP requests. The handler
31-
/// receives each request along with a body reader and ``HTTPResponseSender``.
31+
/// receives each request along with its context, a body and trailers reader, and an ``HTTPResponseSender``.
3232
///
3333
/// ## Example
3434
///
3535
/// ```swift
3636
/// struct EchoHandler: HTTPServerRequestHandler {
3737
/// func handle(
3838
/// request: HTTPRequest,
39-
/// requestBodyAndTrailers: consuming HTTPRequestConcludingAsyncReader,
40-
/// responseSender: consuming HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
39+
/// requestContext: HTTPRequestContext,
40+
/// requestBodyAndTrailers: consuming sending HTTPRequestConcludingAsyncReader,
41+
/// responseSender: consuming sending HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
4142
/// ) async throws {
4243
/// let response = HTTPResponse(status: .ok)
4344
/// let writer = try await responseSender.send(response)
@@ -49,5 +50,5 @@ public protocol HTTPServerProtocol: Sendable, ~Copyable, ~Escapable {
4950
///
5051
/// try await server.serve(handler: EchoHandler())
5152
/// ```
52-
func serve(handler: some HTTPServerRequestHandler<ConcludingRequestReader, ConcludingResponseWriter>) async throws
53+
func serve(handler: some HTTPServerRequestHandler<RequestReader, ResponseWriter>) async throws
5354
}

Sources/HTTPServer/HTTPServerRequestHandler.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ public import HTTPTypes
33
/// A protocol that defines the contract for handling HTTP server requests.
44
///
55
/// ``HTTPServerRequestHandler`` provides a structured way to process incoming HTTP requests and generate appropriate responses.
6-
/// Conforming types implement the ``handle(request:requestBodyAndTrailers:responseSender:)`` method,
6+
/// Conforming types implement the ``handle(request:requestContext:requestBodyAndTrailers:responseSender:)`` method,
77
/// which is called by the HTTP server for each incoming request. The handler is responsible for:
88
///
99
/// - Processing the request headers.
10-
/// - Reading the request body data using the provided ``HTTPRequestConcludingAsyncReader``
10+
/// - Reading the request body data using the provided `RequestReader`
1111
/// - Generating and sending an appropriate response using the response callback
1212
///
1313
/// This protocol fully supports bi-directional streaming HTTP request handling including the optional request and response trailers.
@@ -57,28 +57,30 @@ public import HTTPTypes
5757
/// }
5858
/// ```
5959
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
60-
public protocol HTTPServerRequestHandler<ConcludingRequestReader, ConcludingResponseWriter>: Sendable {
60+
public protocol HTTPServerRequestHandler<RequestReader, ResponseWriter>: Sendable {
6161
/// The ``ConcludingAsyncReader`` to use when reading requests. ``ConcludingAsyncReader/FinalElement``
6262
/// must be an optional `HTTPFields`, and ``ConcludingAsyncReader/Underlying`` must use `Span<UInt8>` as its
6363
/// `ReadElement`.
64-
associatedtype ConcludingRequestReader: ConcludingAsyncReader & ~Copyable & SendableMetatype
65-
where ConcludingRequestReader.Underlying.ReadElement == Span<UInt8>, ConcludingRequestReader.FinalElement == HTTPFields?
64+
associatedtype RequestReader: ConcludingAsyncReader & ~Copyable & SendableMetatype
65+
where RequestReader.Underlying.ReadElement == Span<UInt8>,
66+
RequestReader.FinalElement == HTTPFields?
6667

67-
/// The ``ConcludingAsyncWriter`` to use when reading requests. ``ConcludingAsyncWriter/FinalElement``
68+
/// The ``ConcludingAsyncWriter`` to use when writing responses. ``ConcludingAsyncWriter/FinalElement``
6869
/// must be an optional `HTTPFields`, and ``ConcludingAsyncWriter/Underlying`` must use `Span<UInt8>` as its
6970
/// `WriteElement`.
70-
associatedtype ConcludingResponseWriter: ConcludingAsyncWriter & ~Copyable & SendableMetatype
71-
where ConcludingResponseWriter.Underlying.WriteElement == Span<UInt8>, ConcludingResponseWriter.FinalElement == HTTPFields?
71+
associatedtype ResponseWriter: ConcludingAsyncWriter & ~Copyable & SendableMetatype
72+
where ResponseWriter.Underlying.WriteElement == Span<UInt8>,
73+
ResponseWriter.FinalElement == HTTPFields?
7274

7375
/// Handles an incoming HTTP request and generates a response.
7476
///
7577
/// This method is called by the HTTP server for each incoming client request. Implementations should:
7678
/// 1. Examine the request headers in the `request` parameter
77-
/// 2. Read the request body data from the ``RequestConcludingAsyncReader`` as needed
79+
/// 2. Read the request body data from the `RequestReader` as needed
7880
/// 3. Process the request and prepare a response
7981
/// 4. Optionally call ``HTTPResponseSender/sendInformational(_:)`` as needed
8082
/// 4. Call the ``HTTPResponseSender/send(_:)`` with an appropriate HTTP response
81-
/// 5. Write the response body data to the returned ``HTTPResponseConcludingAsyncWriter``
83+
/// 5. Write the response body data to the returned `ResponseWriter`
8284
///
8385
/// - Parameters:
8486
/// - request: The HTTP request headers and metadata.
@@ -93,7 +95,7 @@ public protocol HTTPServerRequestHandler<ConcludingRequestReader, ConcludingResp
9395
func handle(
9496
request: HTTPRequest,
9597
requestContext: HTTPRequestContext,
96-
requestBodyAndTrailers: consuming sending ConcludingRequestReader,
97-
responseSender: consuming sending HTTPResponseSender<ConcludingResponseWriter>
98+
requestBodyAndTrailers: consuming sending RequestReader,
99+
responseSender: consuming sending HTTPResponseSender<ResponseWriter>
98100
) async throws
99101
}

0 commit comments

Comments
 (0)