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: chunked
and 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
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.
Thanks Sapero for including both an Aurora and Emergence version.
Good stuff!