From 2072fb10d307c086e3d377653b6d2c02f47258ea Mon Sep 17 00:00:00 2001 From: Dennis Toepker Date: Fri, 23 Feb 2024 15:48:33 -0800 Subject: [PATCH] doing HTTP response string truncation manually to support backports Signed-off-by: Dennis Toepker --- .../notifications/core/client/DestinationHttpClient.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt index 1ef5e489..ac2bec93 100644 --- a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt +++ b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt @@ -148,7 +148,10 @@ class DestinationHttpClient { @Throws(IOException::class) fun getResponseString(response: CloseableHttpResponse): String { val entity: HttpEntity = response.entity ?: return "{}" - val responseString = EntityUtils.toString(entity, PluginSettings.maxHttpResponseSize / 2) // Java char is 2 bytes + var responseString = EntityUtils.toString(entity) + if (responseString.length > (PluginSettings.maxHttpResponseSize / 2)) { // Java char is 2 bytes + responseString = responseString.substring(0, PluginSettings.maxHttpResponseSize / 2) + } // DeliveryStatus need statusText must not be empty, convert empty response to {} return if (responseString.isNullOrEmpty()) "{}" else responseString }