diff --git a/ballerina/annotation.bal b/ballerina/annotation.bal index 7e17e0d9..1ee06ddc 100644 --- a/ballerina/annotation.bal +++ b/ballerina/annotation.bal @@ -25,8 +25,8 @@ # + unsubscribeOnShutdown - This flag notifies whether or not to initiate unsubscription when the service is shutting down # + httpConfig - The configuration for the subscriber client used to interact with the discovered/specified hub # + discoveryConfig - HTTP client configurations for resource discovery -# + customParams - Additional parameters, which need to be sent with the subscription request -# + customHeaders - Additional HTTP headers, which need to be sent with the subscription request +# + customParams - Additional parameters, which need to be sent with the subscription/unsubscription request +# + customHeaders - Additional HTTP headers, which need to be sent with the subscription/unsubscription request # + servicePath - The generated service-path if the service-path is not provided. This is auto-generated at the compile-time. public type SubscriberServiceConfiguration record {| string|[string, string] target?; diff --git a/ballerina/subscriber_client.bal b/ballerina/subscriber_client.bal index a9b91cc4..08f8c9fd 100644 --- a/ballerina/subscriber_client.bal +++ b/ballerina/subscriber_client.bal @@ -64,7 +64,8 @@ public isolated client class SubscriptionClient { returns SubscriptionChangeResponse|SubscriptionInitiationError { http:Client httpClient = self.httpClient; SubscriptionPayload payload = buildSubscriptionPayload(MODE_UNSUBSCRIBE, unsubscriptionRequest); - http:Response|error response = httpClient->post("", payload, mediaType = mime:APPLICATION_FORM_URLENCODED); + http:Response|error response = httpClient->post("", payload, + headers = unsubscriptionRequest.customHeaders, mediaType = mime:APPLICATION_FORM_URLENCODED); return processHubResponse(self.url, MODE_UNSUBSCRIBE, unsubscriptionRequest.topic, response); } @@ -91,11 +92,11 @@ isolated function buildSubscriptionPayload(string mode, SubscriptionChangeReques if subscriptionReq.leaseSeconds != 0 { payload.hub\.lease_seconds = subscriptionReq.leaseSeconds.toString(); } - map? customParams = subscriptionReq.customParams; - if customParams is map { - foreach var ['key, value] in customParams.entries() { - payload['key] = value; - } + } + map? customParams = subscriptionReq.customParams; + if customParams is map { + foreach var ['key, value] in customParams.entries() { + payload['key] = value; } } return payload; diff --git a/ballerina/tests/subscription_initiation_test.bal b/ballerina/tests/subscription_initiation_test.bal index 3dcda463..d494f289 100644 --- a/ballerina/tests/subscription_initiation_test.bal +++ b/ballerina/tests/subscription_initiation_test.bal @@ -56,17 +56,6 @@ service /common on new http:Listener(9192) { } check caller->respond(); } - - isolated resource function post hub/additional/unsub(http:Caller caller, http:Request request) returns error? { - map params = check request.getFormParams(); - foreach var ['key, _] in self.expectedAdditionalParams { - test:assertTrue(!params.hasKey('key), "unexpected additional parameter present"); - } - foreach var [header, _] in self.expectedAdditionalHeaders { - test:assertTrue(!request.hasHeader(header), "unexpected additional header present"); - } - check caller->respond(); - } } isolated function getServiceAnnotationConfig(string|[string, string] target) returns SubscriberServiceConfiguration { @@ -239,7 +228,7 @@ isolated function testUnSubscriptionInitiationDisable() returns error? { } isolated function testUnSubscriptionInitiationSuccessWithAdditionalParams() returns error? { SubscriberServiceConfiguration config = { - target: ["http://127.0.0.1:9192/common/hub/additional/unsub", COMMON_TOPIC], + target: ["http://127.0.0.1:9192/common/hub/additional", COMMON_TOPIC], leaseSeconds: 36000, callback: CALLBACK, unsubscribeOnShutdown: true diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 823c9a97..e47ddf41 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -280,8 +280,8 @@ should be `websub:SubscriberServiceConfig` a service-level-annotation for `websu # + unsubscribeOnShutdown - This flag notifies whether or not to initiate unsubscription when the service is shutting down # + httpConfig - The configuration for the subscriber client used to interact with the discovered/specified hub # + discoveryConfig - HTTP client configurations for resource discovery -# + customParams - Additional parameters, which need to be sent with the subscription request -# + customHeaders - Additional HTTP headers, which need to be sent with the subscription request +# + customParams - Additional parameters, which need to be sent with the subscription/unsubscription request +# + customHeaders - Additional HTTP headers, which need to be sent with the subscription/unsubscription request # + servicePath - The generated service-path if the service-path is not provided. This is auto-generated at the compile-time public type SubscriberServiceConfiguration record {| string|[string, string] target?;