Skip to content

Commit 277b511

Browse files
authored
Rename HTTPServerProtocol to HTTPServer (#46)
This PR renames `HTTPServerProtocol` to `HTTPServer`, and updates some docs.
1 parent 67b5141 commit 277b511

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/// A context object that carries additional information about an HTTP request.
22
///
33
/// `HTTPRequestContext` provides a way to pass metadata through the HTTP request pipeline.
4-
public struct HTTPRequestContext: Sendable {}
4+
public struct HTTPRequestContext: Sendable {
5+
public init() {}
6+
}

Sources/HTTPServer/HTTPServerProtocol.swift renamed to Sources/HTTPServer/HTTPServer.swift

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ public import HTTPTypes
1515
public 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
}

Sources/HTTPServer/HTTPServerClosureRequestHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public struct HTTPServerClosureRequestHandler<
8888
}
8989

9090
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
91-
extension HTTPServerProtocol {
91+
extension HTTPServer {
9292
/// Starts an HTTP server with a closure-based request handler.
9393
///
9494
/// This method provides a convenient way to start an HTTP server using a closure to handle incoming requests.

Sources/HTTPServer/NIOHTTPServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import X509
7676
/// }
7777
/// ```
7878
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
79-
public struct NIOHTTPServer: HTTPServerProtocol {
79+
public struct NIOHTTPServer: HTTPServer {
8080
public typealias RequestReader = HTTPRequestConcludingAsyncReader
8181
public typealias ResponseWriter = HTTPResponseConcludingAsyncWriter
8282

0 commit comments

Comments
 (0)