Figure 19-6 The source code for the client (Linux web host)
Figure 19-6 The source code for the client used here is relatively short and simple thanks again to the libraries that come with Python. The httplib and urllib2 libraries are used to look after the communication side of things, with the StringIO and gzip libraries providing the classes needed to carry out the decompression of the data stream. These are all declared in the imports at the start of the source: import httplib import urllib2 import StringIO import gzip Of course for the system to work, there will have to be compression server-side. An address that s known to support gzip and serve fairly big feed files is placed in the string URI: URI = http://thorne.id.au/feeds Although it s possible to use print statements to show what data is being passed around, HTTPConnection has a convenient debug option, which will send messages to the console: httplib.HTTPConnection.debuglevel = 1 Before the transaction can be initiated, the client has to prepare a request to pass to the server. The urllib2 library has a class Request which makes this fairly easy. Here a Request object is created, and then the value of its Accept-Encoding header is set to gzip : request = urllib2.Request(URI) request.add_header( Accept-Encoding , gzip ) GET/feeds HTTP/1.0 Client Accept-encoding: gzip Server Request HTTP/1.0 200 OK Content-encoding: gzip Response Data gunzip gzip Feed Feed 229 Systematic Overview
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.