You are manually setting the TIdHTTP.Request.AcceptEncoding
property to tell the webserver that it is OK to send a compressed response even if TIdCompressorZLib
is not actually ready to handle it. In your case, the TIdCompressorZLib.IsReady
property is likely reporting False on OSX, but True on Windows.
In January 2016, Indy was updated to dynamically load the ZLib library on-demand the first time ZLib is used (SVN rev 5330). That change broke TIdCompressorZLib
, which was later fixed in February 2016 (SVN rev 5343). I do not know if that fix is in Berlin or not. Try installing the latest SVN rev and see if the problem continues (instructions and download).
When using the TIdHTTP.Compressor
property, DO NOT set the Request.AcceptEncoding
property manually at all:
with TIdHTTP.Create(nil) do begin
HandleRedirects := true;
Compressor := TIdCompressorZLib.Create(nil);
// Request.AcceptEncoding := 'gzip, deflate'; // <-- here
Data := Get('http://google.com.au');
Compressor.Free;
Free;
WriteLn(Data);
end;
Leave Request.AcceptEncoding
blank, and let TIdHTTP
update it internally if the assigned Compressor
is actually ready to handle compressed responses.
BTW, you are leaking the TIdHTTP
and TIdCompressorZLib
objects if TIdHTTP.Get()
raises an exception on failure. You should be using try/finally
blocks:
with TIdHTTP.Create(nil) do
try
HandleRedirects := true;
Compressor := TIdCompressorZLib.Create(nil);
try
// Request.AcceptEncoding := 'gzip, deflate';
Data := Get('http://google.com.au');
finally
Compressor.Free;
end;
finally
Free;
end;
WriteLn(Data);