| ITCompression |
| Integrating with WWHTTP |
Rick mentioned in his Blog that you can utlilise the built in compression on IIS servers in order to speed up data transfer rates using his WWHTTP class. In order to do that you need to tell the IIS server to compress the reply data. To do that, you need to send a header in your request. I have cut and pasted this form Ricks Blog.
_______________________
o = CREATEOBJECT("wwHTTP")
o.cexTRAHEADERS = "Accept-Encoding: gzip, deflate" + CHR(13)+ CHR(10)
? o.HttpGet("http://localhost/pricing.htm")
For those not using wwHTTP, with plain WinInet code you supply the headers as part of the HttpSendRequest() method:
lnRetval=HttpSendRequest(hHTTPResult,tcHeaders,LEN(tcHeaders),lcPostBuffer,tnPostSize)
_______________________
WARNING: This class currently does not support the deflate format. I'm not sure why it doesn't work but I'll nut it out. So you must make sure that the header you use is,
"Accept-Encoding: gzip"
AND NOT
"Accept-Encoding: gzip, deflate"
All will still work fine as IIS can send in either format. The header stipulates which method you want IIS to use. By just including the gzip work you are telling IIS to only use gzip.
The next thing you need to do is decompress the data when it returns. Unfortunately the WININET.DLL does not automatically decompress the returned data. To do this you just need to hook into the appropriate place in the wwhttp class. Assuming you sublassed it, an example of how you would do this is as follows.
FUNCTION HTTPGet()
lcData =dodefault()
* Get the header that tells us the compression type. This method
* will handle either gzip or deflate (zlib)
lnLine = Atline(Upper("Content-Encoding:"),Upper(THIS.chttpheaders))
If lnLine > 0
lcEncoding = Upper(Mline(THIS.chttpheaders,lnLine))
If ('GZIP' $ lcEncoding) Or 'DEFLATE' $ lcEncoding
loCompression = Createobject('IT_Compression')
lcUnCompressedString = ""
lcMethod = ""
llSuccess = .f.
lcErrorMessage = ""
Do case
Case 'DEFLATE' $ lcEncoding
lcMethod = 'DEFLATE'
* Doesn't work of IIS encoded deflate for some reason
* Still working this one out
*llSuccess = loCompression.UncompressString(@lcData, @lcUnCompressedString)
lcErrorMessage = "Deflate is not currently supported"
Case 'GZIP' $ lcEncoding
lcMethod = 'GZIP'
llSuccess = loCompression.gzUncompressString(@lcData, @lcUnCompressedString)
lcErrorMessage = loCompression.cErrorMsg
Endcase
If llSuccess
lcData = lcUnCompressedString
Else
This.nError = -1
THIS.cerrormsg="The data is compressed using "+lcMethod+ " but could not be decoded."+lcErrorMessage
Endif
lcUnCompressedString = ""
Release loCompression
Endif
Endif
RETURN lcData