delphi-rest-client-api icon indicating copy to clipboard operation
delphi-rest-client-api copied to clipboard

Support for send GZIP data

Open RobertoSchneiders opened this issue 10 years ago • 2 comments

I'm using the api to send a large amount of data and need to compress the data with gzip. From what I understand the API supports GZIP in return through EnabledCompression but not in the sending.

Due to problems with XE2 in TIdCompressorZLib I'm using TZCompressionStream (System.ZLib.pas).

It would be great if we could encapsulate this routine in RESTClient.

What do you think?

RobertoSchneiders avatar Mar 11 '14 13:03 RobertoSchneiders

I'm not familiar with the ZLib library, show me the code you are using with TZCompressionStream.

Maybe we can include that in TRestClient.DoRequest thus becomes transparent and independent of the connection layer used.

We can also define events to customize the compression and / or use other alternatives of compression.

fabriciocolombo avatar Jul 30 '14 00:07 fabriciocolombo

Does that help you?

uses
  System.ZLib; 
procedure Compactar(Original, Compactado: TStringStream);
const
  GZIP = 31;
var
  CompactadorGZip: TZCompressionStream;
begin
  CompactadorGZip := TZCompressionStream.Create(Compactado, zcMax, GZIP);
  try
    CompactadorGZip.CopyFrom(Original, Original.Size)
  finally
    CompactadorGZip.Free;
  end;
end;

I am also setting the content-type that way

.ContentType('gzip/json')

RobertoSchneiders avatar Jul 30 '14 12:07 RobertoSchneiders