Skip to content

Commit 0be469b

Browse files
authored
Add very basic documentation on how to enable compression (#1388)
1 parent e1a0025 commit 0be469b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/faqs.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,29 @@ an RPC. Users may set a time limit (either a deadline or a timeout) on the
130130
completed before the time limit will be failed with status code 4
131131
('deadline exceeded').
132132

133+
## Compression
134+
135+
gRPC Swift supports compression.
136+
137+
### How to enable compression for the Client
138+
139+
You can configure compression via the messageEncoding property on CallOptions:
140+
141+
```swift
142+
// Configure encoding
143+
let encodingConfiguration = ClientMessageEncoding.Configuration(
144+
forRequests: .gzip, // use gzip for requests
145+
acceptableForResponses: .all, // accept all supported algorithms for responses
146+
decompressionLimit: .ratio(20) // reject messages and fail the RPC if a response decompresses to over 20x its compressed size
147+
)
148+
149+
// Enable compression with configuration
150+
let options = CallOptions(messageEncoding: .enabled(encodingConfiguration))
151+
152+
// Use the options to make a request
153+
let rpc = echo.get(request, callOptions: options)
154+
// ...
155+
```
133156

134157
[grpc-conn-states]: connectivity-semantics-and-api.md
135158
[grpc-keepalive]: keepalive.md

0 commit comments

Comments
 (0)