From 7734f95331d2a1640d827e32db5c16268651be75 Mon Sep 17 00:00:00 2001 From: Chris Simmons Date: Fri, 1 May 2026 18:48:15 -0400 Subject: [PATCH] Fix UTF-8 handling for cfhttp responses (ByteArrayOutputStream vs binary) --- com/api.cfc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/com/api.cfc b/com/api.cfc index 6cf61fa..aa01570 100644 --- a/com/api.cfc +++ b/com/api.cfc @@ -100,11 +100,13 @@ component accessors="true" { apiResponse[ 'statusCode' ] = listFirst( rawResponse.statuscode, ' ' ); apiResponse[ 'rawData' ] = rawResponse.filecontent; - if ( - find( 'application/x-amz-json', rawResponse.mimeType ) && - !isSimpleValue( apiResponse.rawData ) - ) { - apiResponse.rawData = toString( apiResponse.rawData, 'utf-8' ); + // Handle CF returning a Java ByteArrayOutputStream (common with AWS responses) + if ( getMetadata( apiResponse.rawData ).getName() == "java.io.ByteArrayOutputStream" ) { + apiResponse.rawData = apiResponse.rawData.toString( "utf-8" ); + } + // Handle true binary data + else if ( isBinary( apiResponse.rawData ) ) { + apiResponse.rawData = toString( apiResponse.rawData, "utf-8" ); } apiResponse[ 'host' ] = arguments.host;