1
1
/**
2
- * @fileoverview grpc-web Interceptor.
2
+ * @fileoverview grpc-web client interceptors.
3
+ *
4
+ * The type of interceptors is determined by the response type of the RPC call.
5
+ * gRPC-Web has two generated clients for one service:
6
+ * FooServiceClient and FooServicePromiseClient. The response type of
7
+ * FooServiceClient is ClientReadableStream for BOTH unary calls and server
8
+ * streaming calls, so StreamInterceptor is expected to be used for intercepting
9
+ * FooServiceClient calls. The response type of PromiseClient is Promise, so use
10
+ * UnaryInterceptor for PromiseClients.
3
11
*/
4
12
5
13
goog . module ( 'grpc.web.Interceptor' ) ;
@@ -11,6 +19,18 @@ const Request = goog.require('grpc.web.Request');
11
19
const UnaryResponse = goog . require ( 'grpc.web.UnaryResponse' ) ;
12
20
13
21
/**
22
+ * Interceptor for RPC calls with response type `UnaryResponse`.
23
+ * An example implementation of UnaryInterceptor
24
+ * <pre>
25
+ * TestUnaryInterceptor.prototype.intercept = function(request, invoker) {
26
+ * const newRequest = ...
27
+ * return invoker(newRequest).then((response) => {
28
+ * // Do something with response.getMetadata
29
+ // Do something with response.getResponseMessage
30
+ * return response;
31
+ * });
32
+ * };
33
+ * </pre>
14
34
* @interface
15
35
*/
16
36
const UnaryInterceptor = function ( ) { } ;
@@ -28,6 +48,14 @@ UnaryInterceptor.prototype.intercept = function(request, invoker) {};
28
48
29
49
30
50
/**
51
+ * Interceptor for RPC calls with response type `ClientReadableStream`.
52
+ *
53
+ * Two steps to create a stream interceptor:
54
+ * <1>Create a new subclass of ClientReadableStream that wraps around the
55
+ * original stream and overrides its methods. <2>Create a new subclass of
56
+ * StreamInterceptor. While implementing the
57
+ * StreamInterceptor.prototype.intercept method, return the wrapped
58
+ * ClientReadableStream.
31
59
* @interface
32
60
*/
33
61
const StreamInterceptor = function ( ) { } ;
0 commit comments