HTTP Request for Binary Object casts fileContent to String
Description
The binary object should be retained and not stringified.
Activity
Show:
Brad Wood February 22, 2025 at 8:48 PM
Edited
Doesn’t the cfhttp tag cast the filecontent byte array into a string when the response content-type is of the string variety?
Actually, it seems the JDK’s http client is doing this per the docs on the .body() method
String java.net.http.HttpResponse.body()
Returns the body. Depending on the type of T, the returned body may represent the body after it was read (such as byte[], or String, or Path) or it may represent an object with which the body is read, such as an java.io.InputStream.
Seems we’re always typing the body as a string and I’m not sure that’s actually correct as I believe it would always be forcing the response into a string regardless of the response type.
Since we don’t know the response type until we can see the response headers, I think we’d want to leave it raw and then determine what to do with it later based on the response headers.
Note, Lucee and Adobe both have a text key in their cfhttp struct, which should be closely tied to this logic, since that key is based on the response content-type. It seems BL is missing this key entirely from our struct. cc
Fixed
Pinned fields
Click on the next to a field label to start pinning.
The binary object should be retained and not stringified.