From 364d1700c41d2c0c9dae24739a63b02ea790cf57 Mon Sep 17 00:00:00 2001 From: Dennis Toepker Date: Fri, 23 Feb 2024 15:33:52 -0800 Subject: [PATCH] doing string truncation for max http response size manually to support backporting 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 }