IonicWind Software

Aurora Compiler => Tips and Tricks => Topic started by: sapero on February 28, 2007, 03:19:50 PM

Title: Using sockets, HTTP and gzip
Post by: sapero on February 28, 2007, 03:19:50 PM
This example shows how to download a file from internet using low level socket functions.
It shows how to parse received HTTP headers placing them in string dictionary, and how to speed up downloading by requesting server side file compression.

To request compression we need to add in request header:"Accept-Encoding: gzip" {plus optional ", deflate"} //without quotations.
If the server supports compression and can compress the requested file, will add this line in response headers:Content-Encoding: gzip
The format of gzipped file can be raw (just rename the file to .gz) or chunked, we need to check existence ofTransfer-Encoding: chunkedand eventually merge all chunks and truncate the file.

To un-gzip - I've used zlib1.dll available on windows xp/vista, or free to download and use from http://zlib.net
As well this example uses structured exceptions handling to break on any error.

It downloads from three servers:
1. ionicwind.com - chunked gzip
2. google.com - gzip
3. w3.org - no compression
Title: Re: Using sockets, HTTP and gzip
Post by: sapero on March 01, 2007, 07:45:56 AM
The attachment has been modified - the Unchunk function call has moved right after downloading, before decompressing. Any file can be chunked, uncompressed html too!.
The format of "deflate" compression is same as gzip (function inflate failed) - updated.
Added emergence version.
Title: Re: Using sockets, HTTP and gzip
Post by: Ionic Wind Support Team on March 01, 2007, 08:11:57 AM
Thanks Sapero for including both an Aurora and Emergence version.

Good stuff!