Skip to content

Commit

Permalink
Add functionality to log HTTP headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed Dec 13, 2024
1 parent 9ac116b commit e1a0620
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/kafka-hub/subscriber/subscriber_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ballerina/websubhub;
final string topicName = os:getEnv("TOPIC_NAME") == "" ? "priceUpdate" : os:getEnv("TOPIC_NAME");
final string hubUrl = os:getEnv("HUB_URL") == "" ? "https://lb:9090/hub" : os:getEnv("HUB_URL");
final boolean unsubOnShutdown = os:getEnv("UNSUB_ON_SHUTDOWN") == "true";
final boolean logHeaders = os:getEnv("LOG_HEADERS") == "true";

type OAuth2Config record {|
string tokenUrl;
Expand Down Expand Up @@ -106,6 +107,13 @@ service /JuApTOXq19 on securedSubscriber {
remote function onEventNotification(websub:ContentDistributionMessage event) returns error? {
json notification = check event.content.ensureType();
log:printInfo("Received notification", content = notification);
if logHeaders {
map<string|string[]>? receivedHeaders = event.headers;
if receivedHeaders is () {
return;
}
log:printInfo("Received headers: ", headers = receivedHeaders);
}
}
}

Expand Down

0 comments on commit e1a0620

Please sign in to comment.