Răsfoiți Sursa

Add very basic documentation on how to enable compression (#1388)

Wolfgang Lutz 3 ani în urmă
părinte
comite
0be469bd8e
1 a modificat fișierele cu 23 adăugiri și 0 ștergeri
  1. 23 0
      docs/faqs.md

+ 23 - 0
docs/faqs.md

@@ -130,6 +130,29 @@ an RPC. Users may set a time limit (either a deadline or a timeout) on the
 completed before the time limit will be failed with status code 4
 ('deadline exceeded').
 
+## Compression
+
+gRPC Swift supports compression.
+
+### How to enable compression for the Client
+
+You can configure compression via the messageEncoding property on CallOptions:
+
+```swift
+// Configure encoding
+let encodingConfiguration = ClientMessageEncoding.Configuration(
+  forRequests: .gzip, // use gzip for requests
+  acceptableForResponses: .all, // accept all supported algorithms for responses
+  decompressionLimit: .ratio(20) // reject messages and fail the RPC if a response decompresses to over 20x its compressed size
+)
+
+// Enable compression with configuration
+let options = CallOptions(messageEncoding: .enabled(encodingConfiguration))
+
+// Use the options to make a request
+let rpc = echo.get(request, callOptions: options)
+// ...
+```
 
 [grpc-conn-states]: connectivity-semantics-and-api.md
 [grpc-keepalive]: keepalive.md