I have written a server daemon (Linux, Ubuntu) which communicates with PHP as frontend layer.
Recently, i updated both FPC and the Indy library to its FPC 2.6.0 and Indy to the trunk version (before i was using the Tiburon branch).
All compiled, and everything looked fine, but, when writing to an IOHandler, nothing gets received (by the PHP client), the client will report that 0 bytes were received.
After diving into the problem, i saw that when using the write methods from the IOHandler, the encoding is validated and converted before the response is sent, in the ToBytes() method in IdGlobal.pas.
Now if i comment out the conversion lines in the ToBytes() routines;
if ASrcEncoding <> ADestEncoding then begin
LBytes := TIdTextEncoding.Convert(ASrcEncoding, ADestEncoding, LBytes);
This time, the PHP client receives the response.
My question is, how can i configure my Indy tcp server or IOHandlers to stop encoding the data ?
Indy calls
TIdTextEncoding.Convert()when it thinks the two encodings are different so bytes can be converted from one charset to another. However, Indy does not yet detect when twoTIdTextEncodingobjects represent the same charset so the conversion can be skipped. That is mainly due to a limitation in Embarcadero’sSysUtils.TEncodingclass in Delphi 2009-XE, which does not expose that information (in Delphi XE2,TEncodingreceived newEncodingNameandCodePageproperties, but Indy has not been updated to utilize them yet). Indy’sTIdTextEncodingclass is an alias forTEncodingin Delphi 2009+, and is modeled afterTEncodingin Delphi 5-2007 and FreePascal, in order to maintain a single API throughout Indy’s codepage.Indy currently just compares
TIdTextEncodingobject pointers to each other, which is fine when using the standard encodings from theTIdTextEncodingclass properties, as they are implemented as singleton objects in memory. However, if you mix inTIdTextEncodingobjects that are obtained by theTIdTextEncoding.GetEncoding()method, such as from Indy’sCharsetToEncoding()function, then the object pointers will not match even if their charsets do. In ideal conditions, that would be a no-op conversion from charset to Unicode back to the same charset.However, under FreePascal,
TIdTextEncodinguses the ICONV library, and Indy’s ICONV support is incomplete. Conversions are implemented, but full error handling is not implemented yet, largely due to issues with accessing theerrnovariable on different platforms, which ICONV uses for extended error reporting. Not all of ICONV’s errors are fatal, but Indy cannot detect them yet.Worse,
TEncodingis set up to NOT throw exceptions when conversion errors occur, only when buffer errors occur (shame on Embarcadero for that). If a data conversion error occurs,TEncodingjust returns empty data. We had to maintain that behavior inTIdTextEncodingunder non-D2009+ environments, like FreePascal. I suppose Indy could be updated to check for that condition internally and raise its own exception when needed.To answer your question, there is nothing you can do to tell Indy to skip the call to
TIdTextEncoding.Convert(). You would have to comment it out and recompile Indy for the time being. This is a known issue in the current Indy release, and there has been some work done to address it, but there is no ETA yet on when that will be ready for public use. In Indy 11, we are likely going to drop support forTEncodingand implement our own charset engine natively in Indy, at least for commonly used charsets. That way we are not tied to any particular platform-specific APIs anymore. But we have not even started work on Indy 11 yet, or even decided what its feature set will be.