File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
packages/eventstream-handler-node/src Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ export interface EventSigningStreamOptions extends TransformOptions {
8
8
eventMarshaller : EventMarshaller ;
9
9
}
10
10
11
+ /**
12
+ * A transform stream that signs the eventstream
13
+ */
11
14
export class EventSigningStream extends Transform {
12
15
private priorSignature : string ;
13
16
private eventSigner : EventSigner ;
Original file line number Diff line number Diff line change @@ -21,6 +21,13 @@ export interface EventStreamPayloadHandlerOptions {
21
21
utf8Decoder : Decoder ;
22
22
}
23
23
24
+ /**
25
+ * A handler that control the eventstream payload flow:
26
+ * 1. Pause stream for initial attempt.
27
+ * 2. Close the stream is attempt fails.
28
+ * 3. Start piping payload when connection is established.
29
+ * 4. Sign the payload after payload stream starting to flow.
30
+ */
24
31
export class EventStreamPayloadHandler implements IEventStreamPayloadHandler {
25
32
private readonly eventSigner : Provider < EventSigner > ;
26
33
private readonly eventMarshaller : EventMarshaller ;
@@ -50,12 +57,16 @@ export class EventStreamPayloadHandler implements IEventStreamPayloadHandler {
50
57
try {
51
58
result = await next ( args ) ;
52
59
} catch ( e ) {
60
+ // Close the payload stream otherwise the retry would hang
61
+ // because of the previous connection.
53
62
request . body . end ( ) ;
54
63
throw e ;
55
64
}
65
+ // If response is successful, start piping the payload stream
56
66
const match = ( request . headers [ "authorization" ] || "" ) . match (
57
67
/ S i g n a t u r e = ( [ \w ] + ) $ /
58
68
) ;
69
+ // Sign the eventstream based on the signature from initial request.
59
70
const priorSignature = ( match || [ ] ) [ 1 ] ;
60
71
const signingStream = new EventSigningStream ( {
61
72
priorSignature,
You can’t perform that action at this time.
0 commit comments