RTC Forums

Subscription => Support => Topic started by: ManfredPfeiffer on September 03, 2012, 09:47:01 PM



Title: Compression on HTTP Server
Post by: ManfredPfeiffer on September 03, 2012, 09:47:01 PM
Danijel,

I am writing a HTTP server which sends SVG images to mobile devices. Is there any way to send the response compressed (gzip)?

Kind regards,
Manfred


Title: Re: Compression on HTTP Server
Post by: D.Tkalcec (RTC) on September 03, 2012, 09:54:15 PM
You can set HTTP headers to let the Client know what your content will be compressed and use a compression library to compress the content body before you send it out. Because only the content body is being compressed when using "gzip" over HTTP/S, you have full control over the process.

Best Regards,
Danijel Tkalcec


Title: Re: Compression on HTTP Server
Post by: ManfredPfeiffer on September 04, 2012, 05:24:18 AM
Could your ZCompress_Str be used for the compression?


Title: Re: Compression on HTTP Server
Post by: D.Tkalcec (RTC) on September 04, 2012, 08:34:34 AM
Besauce the RTC SDK uses "zlib", you may be able to use the included ZCompress/ZDecompress functions to work with "deflate" Content-Encoding, but I don't think it will work for "gzip", because that is a different format.

Best Regards,
Danijel Tkalcec


Title: Re: Compression on HTTP Server
Post by: D.Tkalcec (RTC) on September 04, 2012, 10:08:25 AM
I've just ran a short test using the RTC SDK v6.0 RC2 and this seems to be working for sending out "deflate" compressed files:
Code:
uses rtcInfo, rtcZLib;

function SendDeflateCompressed(Srv:TRtcDataServer; const filename:String);
  begin
  Srv.Response['Content-Encoding']:='deflate';
  Srv.WriteEx(ZCompress_Ex(Read_FileEx(filename),zcDefault));
  end;

Here is the same for RTC SDK v5.x and older:
Code:
uses rtcInfo, rtcZLib;

function SendDeflateCompressed(Srv:TRtcDataServer; const filename:String);
  begin
  Srv.Response['Content-Encoding']:='deflate';
  Srv.Write(ZCompress_Str(Read_File(filename),zcDefault));
  end;

Best Regards,
Danijel Tkalcec


Title: Re: Compression on HTTP Server
Post by: ManfredPfeiffer on September 04, 2012, 11:16:28 AM
"Deflate" works fine with Zcompress_str - thank you very much!


Title: Re: Compression on HTTP Server
Post by: ManfredPfeiffer on September 04, 2012, 11:19:05 AM
Sorry - didn't see your last post before I replied. Is it possible to integrate compression into the properties of HTTPServer (similar to Intraweb)?

Kind regards,
Manfred


Title: Re: Compression on HTTP Server
Post by: D.Tkalcec (RTC) on September 04, 2012, 12:46:29 PM
TRtcHttpServer is a general-purpose HTTP/S Server, where you have full control over all data going in and out. Adding support for a specific content compression/decompression algorithm at such a low level would not be possible, without restricting what you can do with the components.

PS. TRtcServerModule and TRtcClientModule components have built-in automatic compression and decompression support, because all data going in and out is under component control (and not user control).

Best Regards,
Danijel Tkalcec