You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/async-await.md
+29-6
Original file line number
Diff line number
Diff line change
@@ -65,12 +65,14 @@ If the library code throws from the `HTTPClientRequest` creation or the request
65
65
The new `HTTPClientRequest` has a new body type, that is wrapper around an internal enum. This allows us to evolve this type for use-cases that we are not aware of today.
66
66
67
67
```swift
68
-
publicstructBody {
69
-
staticfuncbytes<S: Sequence>(_sequence: S) -> Body where S.Element==UInt8
70
-
71
-
staticfuncstream<S: AsyncSequence>(_sequence: S) -> Body where S.Element== ByteBuffer
72
-
73
-
staticfuncstream<S: AsyncSequence>(_sequence: S) -> Body where S.Element==UInt8
68
+
extensionHTTPClientRequest {
69
+
publicstructBody {
70
+
staticfuncbytes<S: Sequence>(_sequence: S) -> Body where S.Element==UInt8
71
+
72
+
staticfuncstream<S: AsyncSequence>(_sequence: S) -> Body where S.Element== ByteBuffer
73
+
74
+
staticfuncstream<S: AsyncSequence>(_sequence: S) -> Body where S.Element==UInt8
75
+
}
74
76
}
75
77
```
76
78
@@ -145,6 +147,27 @@ extension HTTPClient {
145
147
}
146
148
```
147
149
150
+
Usage example:
151
+
152
+
```swift
153
+
var request =HTTPClientRequest(url: "https://swift.org")
154
+
request.method= .POST
155
+
request.headers= [
156
+
"content-type":"text/plain; charset=UTF-8"
157
+
"x-my-fancy-header":"super-awesome"
158
+
]
159
+
request.body= .sequence("Hello world!".utf8)
160
+
161
+
var response =tryawait client.execute(request, deadline: .now() + .seconds(5))
162
+
163
+
switch response.status {
164
+
case .ok:
165
+
let body =tryawait response.body.collect(maxBytes: 1024*1024)
166
+
default:
167
+
throw MyUnexpectedHTTPStatusError
168
+
}
169
+
```
170
+
148
171
-**Why do we have a deadline in the function signature?**
149
172
Task deadlines are not part of the Swift 5.5 release. However we think that they are an important tool to not overload the http client accidentally. For this reason we will not default them.
150
173
-**What happened to the Logger?** We will use Task locals to propagate the logger metadata. @slashmo and @ktoso are currently working on this.
0 commit comments