Skip to content

Commit 5e3e58d

Browse files
authored
Use Docc for documentation (#613)
Motivation Documentation is nice, and we can help support users by providing useful clear docs. Modifications Add Docc to 5.6 and later builds Make sure symbol references work Add overview docs Result Nice rendering docs
1 parent df87a86 commit 5e3e58d

File tree

15 files changed

+698
-53
lines changed

15 files changed

+698
-53
lines changed

‎Package.swift‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:5.6
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the AsyncHTTPClient open source project
@@ -28,6 +28,7 @@ let package = Package(
2828
.package(url:"https://github.com/apple/swift-nio-transport-services.git", from:"1.11.4"),
2929
.package(url:"https://github.com/apple/swift-log.git", from:"1.4.0"),
3030
.package(url:"https://github.com/apple/swift-atomics.git", from:"1.0.2"),
31+
.package(url:"https://github.com/apple/swift-docc-plugin", from:"1.0.0"),
3132
],
3233
targets:[
3334
.target(name:"CAsyncHTTPClient"),

[email protected]

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// swift-tools-version:5.4
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the AsyncHTTPClient open source project
5+
//
6+
// Copyright (c) 2018-2019 Apple Inc. and the AsyncHTTPClient project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
letpackage=Package(
19+
name:"async-http-client",
20+
products:[
21+
.library(name:"AsyncHTTPClient", targets:["AsyncHTTPClient"]),
22+
],
23+
dependencies:[
24+
.package(url:"https://github.com/apple/swift-nio.git", from:"2.38.0"),
25+
.package(url:"https://github.com/apple/swift-nio-ssl.git", from:"2.14.1"),
26+
.package(url:"https://github.com/apple/swift-nio-http2.git", from:"1.19.0"),
27+
.package(url:"https://github.com/apple/swift-nio-extras.git", from:"1.10.0"),
28+
.package(url:"https://github.com/apple/swift-nio-transport-services.git", from:"1.11.4"),
29+
.package(url:"https://github.com/apple/swift-log.git", from:"1.4.0"),
30+
.package(url:"https://github.com/apple/swift-atomics.git", from:"1.0.2"),
31+
],
32+
targets:[
33+
.target(name:"CAsyncHTTPClient"),
34+
.target(
35+
name:"AsyncHTTPClient",
36+
dependencies:[
37+
.target(name:"CAsyncHTTPClient"),
38+
.product(name:"NIO",package:"swift-nio"),
39+
.product(name:"NIOCore",package:"swift-nio"),
40+
.product(name:"NIOPosix",package:"swift-nio"),
41+
.product(name:"NIOHTTP1",package:"swift-nio"),
42+
.product(name:"NIOConcurrencyHelpers",package:"swift-nio"),
43+
.product(name:"NIOFoundationCompat",package:"swift-nio"),
44+
.product(name:"NIOHTTP2",package:"swift-nio-http2"),
45+
.product(name:"NIOSSL",package:"swift-nio-ssl"),
46+
.product(name:"NIOHTTPCompression",package:"swift-nio-extras"),
47+
.product(name:"NIOSOCKS",package:"swift-nio-extras"),
48+
.product(name:"NIOTransportServices",package:"swift-nio-transport-services"),
49+
.product(name:"Logging",package:"swift-log"),
50+
.product(name:"Atomics",package:"swift-atomics"),
51+
]
52+
),
53+
.testTarget(
54+
name:"AsyncHTTPClientTests",
55+
dependencies:[
56+
.target(name:"AsyncHTTPClient"),
57+
.product(name:"NIOCore",package:"swift-nio"),
58+
.product(name:"NIOConcurrencyHelpers",package:"swift-nio"),
59+
.product(name:"NIOEmbedded",package:"swift-nio"),
60+
.product(name:"NIOFoundationCompat",package:"swift-nio"),
61+
.product(name:"NIOTestUtils",package:"swift-nio"),
62+
.product(name:"NIOSSL",package:"swift-nio-ssl"),
63+
.product(name:"NIOHTTP2",package:"swift-nio-http2"),
64+
.product(name:"NIOSOCKS",package:"swift-nio-extras"),
65+
.product(name:"Logging",package:"swift-log"),
66+
.product(name:"Atomics",package:"swift-atomics"),
67+
],
68+
resources:[
69+
.copy("Resources/self_signed_cert.pem"),
70+
.copy("Resources/self_signed_key.pem"),
71+
]
72+
),
73+
]
74+
)

[email protected]

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// swift-tools-version:5.4
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the AsyncHTTPClient open source project
5+
//
6+
// Copyright (c) 2018-2019 Apple Inc. and the AsyncHTTPClient project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
letpackage=Package(
19+
name:"async-http-client",
20+
products:[
21+
.library(name:"AsyncHTTPClient", targets:["AsyncHTTPClient"]),
22+
],
23+
dependencies:[
24+
.package(url:"https://github.com/apple/swift-nio.git", from:"2.38.0"),
25+
.package(url:"https://github.com/apple/swift-nio-ssl.git", from:"2.14.1"),
26+
.package(url:"https://github.com/apple/swift-nio-http2.git", from:"1.19.0"),
27+
.package(url:"https://github.com/apple/swift-nio-extras.git", from:"1.10.0"),
28+
.package(url:"https://github.com/apple/swift-nio-transport-services.git", from:"1.11.4"),
29+
.package(url:"https://github.com/apple/swift-log.git", from:"1.4.0"),
30+
.package(url:"https://github.com/apple/swift-atomics.git", from:"1.0.2"),
31+
],
32+
targets:[
33+
.target(name:"CAsyncHTTPClient"),
34+
.target(
35+
name:"AsyncHTTPClient",
36+
dependencies:[
37+
.target(name:"CAsyncHTTPClient"),
38+
.product(name:"NIO",package:"swift-nio"),
39+
.product(name:"NIOCore",package:"swift-nio"),
40+
.product(name:"NIOPosix",package:"swift-nio"),
41+
.product(name:"NIOHTTP1",package:"swift-nio"),
42+
.product(name:"NIOConcurrencyHelpers",package:"swift-nio"),
43+
.product(name:"NIOFoundationCompat",package:"swift-nio"),
44+
.product(name:"NIOHTTP2",package:"swift-nio-http2"),
45+
.product(name:"NIOSSL",package:"swift-nio-ssl"),
46+
.product(name:"NIOHTTPCompression",package:"swift-nio-extras"),
47+
.product(name:"NIOSOCKS",package:"swift-nio-extras"),
48+
.product(name:"NIOTransportServices",package:"swift-nio-transport-services"),
49+
.product(name:"Logging",package:"swift-log"),
50+
.product(name:"Atomics",package:"swift-atomics"),
51+
]
52+
),
53+
.testTarget(
54+
name:"AsyncHTTPClientTests",
55+
dependencies:[
56+
.target(name:"AsyncHTTPClient"),
57+
.product(name:"NIOCore",package:"swift-nio"),
58+
.product(name:"NIOConcurrencyHelpers",package:"swift-nio"),
59+
.product(name:"NIOEmbedded",package:"swift-nio"),
60+
.product(name:"NIOFoundationCompat",package:"swift-nio"),
61+
.product(name:"NIOTestUtils",package:"swift-nio"),
62+
.product(name:"NIOSSL",package:"swift-nio-ssl"),
63+
.product(name:"NIOHTTP2",package:"swift-nio-http2"),
64+
.product(name:"NIOSOCKS",package:"swift-nio-extras"),
65+
.product(name:"Logging",package:"swift-log"),
66+
.product(name:"Atomics",package:"swift-atomics"),
67+
],
68+
resources:[
69+
.copy("Resources/self_signed_cert.pem"),
70+
.copy("Resources/self_signed_key.pem"),
71+
]
72+
),
73+
]
74+
)

‎Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest.swift‎

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@
1616
import NIOCore
1717
import NIOHTTP1
1818

19+
/// A representation of an HTTP request for the Swift Concurrency HTTPClient API.
20+
///
21+
/// This object is similar to ``HTTPClient/Request``, but used for the Swift Concurrency API.
1922
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0,*)
2023
publicstructHTTPClientRequest{
24+
/// The request URL, including scheme, hostname, and optionally port.
2125
publicvarurl:String
26+
27+
/// The request method.
2228
publicvarmethod:HTTPMethod
29+
30+
/// The request headers.
2331
publicvarheaders:HTTPHeaders
2432

33+
/// The request body, if any.
2534
publicvarbody:Body?
2635

2736
publicinit(url:String){
@@ -34,6 +43,10 @@ public struct HTTPClientRequest{
3443

3544
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0,*)
3645
extensionHTTPClientRequest{
46+
/// An HTTP request body.
47+
///
48+
/// This object encapsulates the difference between streamed HTTP request bodies and those bodies that
49+
/// are already entirely in memory.
3750
publicstructBody{
3851
@usableFromInline
3952
internalenumMode{
@@ -54,10 +67,20 @@ extension HTTPClientRequest{
5467

5568
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0,*)
5669
extensionHTTPClientRequest.Body{
70+
/// Create an ``HTTPClientRequest/Body-swift.struct`` from a `ByteBuffer`.
71+
///
72+
/// - parameter byteBuffer: The bytes of the body.
5773
publicstaticfunc bytes(_ byteBuffer:ByteBuffer)->Self{
5874
self.init(.byteBuffer(byteBuffer))
5975
}
6076

77+
/// Create an ``HTTPClientRequest/Body-swift.struct`` from a `RandomAccessCollection` of bytes.
78+
///
79+
/// This construction will flatten the bytes into a `ByteBuffer`. As a result, the peak memory
80+
/// usage of this construction will be double the size of the original collection. The construction
81+
/// of the `ByteBuffer` will be delayed until it's needed.
82+
///
83+
/// - parameter bytes: The bytes of the request body.
6184
@inlinable
6285
publicstaticfunc bytes<Bytes:RandomAccessCollection>(
6386
_ bytes:Bytes
@@ -75,6 +98,23 @@ extension HTTPClientRequest.Body{
7598
})
7699
}
77100

101+
/// Create an ``HTTPClientRequest/Body-swift.struct`` from a `Sequence` of bytes.
102+
///
103+
/// This construction will flatten the bytes into a `ByteBuffer`. As a result, the peak memory
104+
/// usage of this construction will be double the size of the original collection. The construction
105+
/// of the `ByteBuffer` will be delayed until it's needed.
106+
///
107+
/// Unlike ``bytes(_:)-1uns7``, this construction does not assume that the body can be replayed. As a result,
108+
/// if a redirect is encountered that would need us to replay the request body, the redirect will instead
109+
/// not be followed. Prefer ``bytes(_:)-1uns7`` wherever possible.
110+
///
111+
/// Caution should be taken with this method to ensure that the `length` is correct. Incorrect lengths
112+
/// will cause unnecessary runtime failures. Setting `length` to ``Length/unknown`` will trigger the upload
113+
/// to use `chunked` `Transfer-Encoding`, while using ``Length/known(_:)`` will use `Content-Length`.
114+
///
115+
/// - parameters:
116+
/// - bytes: The bytes of the request body.
117+
/// - length: The length of the request body.
78118
@inlinable
79119
publicstaticfunc bytes<Bytes:Sequence>(
80120
_ bytes:Bytes,
@@ -93,6 +133,19 @@ extension HTTPClientRequest.Body{
93133
})
94134
}
95135

136+
/// Create an ``HTTPClientRequest/Body-swift.struct`` from a `Collection` of bytes.
137+
///
138+
/// This construction will flatten the bytes into a `ByteBuffer`. As a result, the peak memory
139+
/// usage of this construction will be double the size of the original collection. The construction
140+
/// of the `ByteBuffer` will be delayed until it's needed.
141+
///
142+
/// Caution should be taken with this method to ensure that the `length` is correct. Incorrect lengths
143+
/// will cause unnecessary runtime failures. Setting `length` to ``Length/unknown`` will trigger the upload
144+
/// to use `chunked` `Transfer-Encoding`, while using ``Length/known(_:)`` will use `Content-Length`.
145+
///
146+
/// - parameters:
147+
/// - bytes: The bytes of the request body.
148+
/// - length: The length of the request body.
96149
@inlinable
97150
publicstaticfunc bytes<Bytes:Collection>(
98151
_ bytes:Bytes,
@@ -111,6 +164,17 @@ extension HTTPClientRequest.Body{
111164
})
112165
}
113166

167+
/// Create an ``HTTPClientRequest/Body-swift.struct`` from an `AsyncSequence` of `ByteBuffer`s.
168+
///
169+
/// This construction will stream the upload one `ByteBuffer` at a time.
170+
///
171+
/// Caution should be taken with this method to ensure that the `length` is correct. Incorrect lengths
172+
/// will cause unnecessary runtime failures. Setting `length` to ``Length/unknown`` will trigger the upload
173+
/// to use `chunked` `Transfer-Encoding`, while using ``Length/known(_:)`` will use `Content-Length`.
174+
///
175+
/// - parameters:
176+
/// - sequenceOfBytes: The bytes of the request body.
177+
/// - length: The length of the request body.
114178
@inlinable
115179
publicstaticfunc stream<SequenceOfBytes:AsyncSequence>(
116180
_ sequenceOfBytes:SequenceOfBytes,
@@ -123,6 +187,19 @@ extension HTTPClientRequest.Body{
123187
return body
124188
}
125189

190+
/// Create an ``HTTPClientRequest/Body-swift.struct`` from an `AsyncSequence` of bytes.
191+
///
192+
/// This construction will consume 1kB chunks from the `Bytes` and send them at once. This optimizes for
193+
/// `AsyncSequence`s where larger chunks are buffered up and available without actually suspending, such
194+
/// as those provided by `FileHandle`.
195+
///
196+
/// Caution should be taken with this method to ensure that the `length` is correct. Incorrect lengths
197+
/// will cause unnecessary runtime failures. Setting `length` to ``Length/unknown`` will trigger the upload
198+
/// to use `chunked` `Transfer-Encoding`, while using ``Length/known(_:)`` will use `Content-Length`.
199+
///
200+
/// - parameters:
201+
/// - bytes: The bytes of the request body.
202+
/// - length: The length of the request body.
126203
@inlinable
127204
publicstaticfunc stream<Bytes:AsyncSequence>(
128205
_ bytes:Bytes,
@@ -157,10 +234,12 @@ extension Optional where Wrapped == HTTPClientRequest.Body{
157234

158235
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0,*)
159236
extensionHTTPClientRequest.Body{
237+
/// The length of a HTTP request body.
160238
publicstructLength{
161-
/// size of the request body is not known before starting the request
239+
/// The size of the request body is not known before starting the request
162240
publicstaticletunknown:Self=.init(storage:.unknown)
163-
/// size of the request body is fixed and exactly `count` bytes
241+
242+
/// The size of the request body is known and exactly `count` bytes
164243
publicstaticfunc known(_ count:Int)->Self{
165244
.init(storage:.known(count))
166245
}

‎Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,28 @@
1616
import NIOCore
1717
import NIOHTTP1
1818

19+
/// A representation of an HTTP response for the Swift Concurrency HTTPClient API.
20+
///
21+
/// This object is similar to ``HTTPClient/Response``, but used for the Swift Concurrency API.
1922
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0,*)
2023
publicstructHTTPClientResponse{
24+
/// The HTTP version on which the response was received.
2125
publicvarversion:HTTPVersion
26+
27+
/// The HTTP status for this response.
2228
publicvarstatus:HTTPResponseStatus
29+
30+
/// The HTTP headers of this response.
2331
publicvarheaders:HTTPHeaders
32+
33+
/// The body of this HTTP response.
2434
publicvarbody:Body
2535

36+
/// A representation of the response body for an HTTP response.
37+
///
38+
/// The body is streamed as an `AsyncSequence` of `ByteBuffer`, where each `ByteBuffer` contains
39+
/// an arbitrarily large chunk of data. The boundaries between `ByteBuffer` objects in the sequence
40+
/// are entirely synthetic and have no semantic meaning.
2641
publicstructBody{
2742
privateletbag:Transaction
2843
privateletreference:ResponseRef

0 commit comments

Comments
(0)