@@ -19,15 +19,18 @@ import ballerina/uuid;
19
19
20
20
isolated class SubscriptionHandler {
21
21
private final HttpToWebsubhubAdaptor adaptor ;
22
+ private final Controller hubController ;
22
23
private final readonly & ClientConfiguration clientConfig ;
23
24
24
25
private final boolean isOnSubscriptionAvailable;
25
26
private final boolean isOnSubscriptionValidationAvailable;
26
27
private final boolean isOnUnsubscriptionAvailable;
27
28
private final boolean isOnUnsubscriptionValidationAvailable;
28
29
29
- isolated function init(HttpToWebsubhubAdaptor adaptor , *ClientConfiguration clientConfig ) {
30
+ isolated function init(HttpToWebsubhubAdaptor adaptor , boolean autoVerifySubscription ,
31
+ ClientConfiguration clientConfig ) {
30
32
self .adaptor = adaptor ;
33
+ self .hubController = new (autoVerifySubscription );
31
34
self .clientConfig = clientConfig .cloneReadOnly ();
32
35
string [] methodNames = adaptor .getServiceMethodNames ();
33
36
self .isOnSubscriptionAvailable = methodNames .indexOf (" onSubscription" ) is int ;
@@ -63,17 +66,20 @@ isolated class SubscriptionHandler {
63
66
return ;
64
67
}
65
68
66
- string challenge = uuid : createType4AsString ();
67
- [string , string ? ][] params = [
68
- [HUB_MODE , MODE_SUBSCRIBE ],
69
- [HUB_TOPIC , message .hubTopic ],
70
- [HUB_CHALLENGE , challenge ],
71
- [HUB_LEASE_SECONDS , message .hubLeaseSeconds ]
72
- ];
73
- http : Response subscriberResponse = check sendNotification (message .hubCallback , params , self .clientConfig );
74
- string responsePayload = check subscriberResponse .getTextPayload ();
75
- if challenge != responsePayload {
76
- return ;
69
+ boolean skipIntentVerification = self .hubController .skipSubscriptionVerification (message );
70
+ if ! skipIntentVerification {
71
+ string challenge = uuid : createType4AsString ();
72
+ [string , string ? ][] params = [
73
+ [HUB_MODE , MODE_SUBSCRIBE ],
74
+ [HUB_TOPIC , message .hubTopic ],
75
+ [HUB_CHALLENGE , challenge ],
76
+ [HUB_LEASE_SECONDS , message .hubLeaseSeconds ]
77
+ ];
78
+ http : Response subscriberResponse = check sendNotification (message .hubCallback , params , self .clientConfig );
79
+ string responsePayload = check subscriberResponse .getTextPayload ();
80
+ if challenge != responsePayload {
81
+ return ;
82
+ }
77
83
}
78
84
79
85
VerifiedSubscription verifiedSubscription = {
@@ -115,16 +121,19 @@ isolated class SubscriptionHandler {
115
121
_ = check sendNotification (message .hubCallback , params , self .clientConfig );
116
122
}
117
123
118
- string challenge = uuid : createType4AsString ();
119
- [string , string ? ][] params = [
120
- [HUB_MODE , MODE_UNSUBSCRIBE ],
121
- [HUB_TOPIC , message .hubTopic ],
122
- [HUB_CHALLENGE , challenge ]
123
- ];
124
- http : Response subscriberResponse = check sendNotification (message .hubCallback , params , self .clientConfig );
125
- string responsePayload = check subscriberResponse .getTextPayload ();
126
- if challenge != responsePayload {
127
- return ;
124
+ boolean skipIntentVerification = self .hubController .skipSubscriptionVerification (message );
125
+ if ! skipIntentVerification {
126
+ string challenge = uuid : createType4AsString ();
127
+ [string , string ? ][] params = [
128
+ [HUB_MODE , MODE_UNSUBSCRIBE ],
129
+ [HUB_TOPIC , message .hubTopic ],
130
+ [HUB_CHALLENGE , challenge ]
131
+ ];
132
+ http : Response subscriberResponse = check sendNotification (message .hubCallback , params , self .clientConfig );
133
+ string responsePayload = check subscriberResponse .getTextPayload ();
134
+ if challenge != responsePayload {
135
+ return ;
136
+ }
128
137
}
129
138
130
139
VerifiedUnsubscription verifiedUnsubscription = {
0 commit comments