fabriciocolombo / delphi-rest-client-api

A Delphi REST client API to consume REST services written in any programming language.
Apache License 2.0
380 stars 182 forks source link

Support for send GZIP data #22

Open RobertoSchneiders opened 10 years ago

RobertoSchneiders commented 10 years ago

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?

fabriciocolombo commented 10 years ago

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.

RobertoSchneiders commented 10 years ago

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')