Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.1
// swift-tools-version: 6.2

import PackageDescription

Expand Down
12 changes: 6 additions & 6 deletions Sources/HTTPServer/HTTPServerClosureRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public struct HTTPServerClosureRequestHandler<ConcludingRequestReader: ~Copyable
private let _handler:
nonisolated(nonsending) @Sendable (
HTTPRequest,
consuming HTTPRequestConcludingAsyncReader,
consuming HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
consuming sending HTTPRequestConcludingAsyncReader,
consuming sending HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
) async throws -> Void

/// Creates a new closure-based HTTP request handler.
Expand All @@ -40,8 +40,8 @@ public struct HTTPServerClosureRequestHandler<ConcludingRequestReader: ~Copyable
public init(
handler: nonisolated(nonsending) @Sendable @escaping (
HTTPRequest,
consuming HTTPRequestConcludingAsyncReader,
consuming HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
consuming sending HTTPRequestConcludingAsyncReader,
consuming sending HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
) async throws -> Void
) {
self._handler = handler
Expand All @@ -57,8 +57,8 @@ public struct HTTPServerClosureRequestHandler<ConcludingRequestReader: ~Copyable
/// - responseSender: An ``HTTPResponseSender`` to send the HTTP response.
public func handle(
request: HTTPRequest,
requestBodyAndTrailers: consuming HTTPRequestConcludingAsyncReader,
responseSender: consuming HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
requestBodyAndTrailers: consuming sending HTTPRequestConcludingAsyncReader,
responseSender: consuming sending HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
) async throws {
try await self._handler(request, requestBodyAndTrailers, responseSender)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/HTTPServer/HTTPServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ extension HTTPServerProtocol where RequestHandler == HTTPServerClosureRequestHan
/// }
/// ```
public func serve(
handler: @Sendable @escaping (
handler: nonisolated(nonsending) @Sendable @escaping (
_ request: HTTPRequest,
_ requestBodyAndTrailers: consuming HTTPRequestConcludingAsyncReader,
_ responseSender: consuming HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
_ requestBodyAndTrailers: consuming sending HTTPRequestConcludingAsyncReader,
_ responseSender: consuming sending HTTPResponseSender<HTTPResponseConcludingAsyncWriter>
) async throws -> Void
) async throws {
try await self.serve(handler: HTTPServerClosureRequestHandler(handler: handler))
Expand Down
4 changes: 2 additions & 2 deletions Sources/HTTPServer/HTTPServerRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public protocol HTTPServerRequestHandler: Sendable {
func handle(
// TODO: add request context parameter
request: HTTPRequest,
requestBodyAndTrailers: consuming ConcludingRequestReader,
responseSender: consuming HTTPResponseSender<ConcludingResponseWriter>
requestBodyAndTrailers: consuming sending ConcludingRequestReader,
responseSender: consuming sending HTTPResponseSender<ConcludingResponseWriter>
) async throws
}
24 changes: 12 additions & 12 deletions Tests/HTTPServerTests/HTTPServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ struct HTTPServerTests {
)
try await server.serve { request, requestBodyAndTrailers, responseSender in
_ = try await requestBodyAndTrailers.collect(upTo: 100) { _ in }
// Uncommenting this would cause a "requestReader consumed more than once" error.
//_ = try await requestReader.collect(upTo: 100) { _ in }
// Uncommenting this would cause a "requestBodyAndTrailers consumed more than once" error.
// _ = try await requestBodyAndTrailers.collect(upTo: 100) { _ in }

let responseConcludingWriter = try await responseSender.send(HTTPResponse(status: .ok))
// Uncommenting this would cause a "responseSender consumed more than once" error.
//let responseConcludingWriter2 = try await responseSender.send(HTTPResponse(status: .ok))
// let responseConcludingWriter2 = try await responseSender.send(HTTPResponse(status: .ok))

// Uncommenting this would cause a "requestReader consumed more than once" error.
//_ = try await requestReader.consumeAndConclude { reader in
// var reader = reader
// try await reader.read { elem in }
//}
// Uncommenting this would cause a "requestBodyAndTrailers consumed more than once" error.
// _ = try await requestBodyAndTrailers.consumeAndConclude { reader in
// var reader = reader
// try await reader.read { elem in }
// }

try await responseConcludingWriter.produceAndConclude { writer in
var writer = writer
Expand All @@ -34,10 +34,10 @@ struct HTTPServerTests {
}

// Uncommenting this would cause a "responseConcludingWriter consumed more than once" error.
//try await responseConcludingWriter.writeAndConclude(
// element: [1, 2].span,
// finalElement: HTTPFields(dictionaryLiteral: (.acceptEncoding, "Encoding"))
//)
// try await responseConcludingWriter.writeAndConclude(
// element: [1, 2].span,
// finalElement: HTTPFields(dictionaryLiteral: (.acceptEncoding, "Encoding"))
// )
}
}
}
Loading