blob: 7b1c0fda4888dc1adca2ddbd95e02c6bf0becf81 [file] [log] [blame]
jcgregorio2d66d4f2006-02-07 05:34:14 +00001<html>
2<head>
3 <!--#include virtual="header.html" -->
4 <title>Joe Gregorio | BitWorking | Projects | httplib2.py</title>
5</head>
6<body class='main' id="top" name="top" >
7 <div class="body">
8 <!--#include virtual="titlebar.html" -->
9
10 <div class="content">
11
12 <div class="item">
13
14 <h2>Httplib2</h2>
15 <p>A comprehensive HTTP client library, <code>httplib2.py</code>
16 supports many features left out of other HTTP libraries.
17 </p>
18 <dl>
19 <dt>HTTP and HTTPS</dt>
20 <dd>HTTPS support is only available if the socket module was compiled with SSL support.
21 </dd>
22
23 <dt>Keep-Alive</dt>
24 <dd>Supports HTTP 1.1 Keep-Alive, keeping the socket
25 open and performing multiple requests over the same connection
26 if possible.
27 </dd>
28
29 <dt>Authentication</dt>
30 <dd>The following three types of HTTP Authentication are supported.
31 These can be used over both HTTP and HTTPS.
32 <ul>
33 <li><a href="http://www.faqs.org/rfcs/rfc2617.html">Digest</a></li>
34 <li><a href="http://www.faqs.org/rfcs/rfc2617.html">Basic</a></li>
35 <li><a href="http://www.xml.com/pub/a/2003/12/17/dive.html">WSSE</a></li>
36 </ul>
37 </dd>
38
39 <dt>Caching</dt>
40 <dd>The module can optionally operate with a private
41 cache that understands the Cache-Control: header and
42 uses both the ETag and Last-Modified cache validators.
43 </dd>
44
45 <dt>All Methods</dt>
46 <dd>The module can handle any HTTP request method, not just GET and POST.</dd>
47
48 <dt>Redirects</dt>
49 <dd>Automatically follows 3XX redirects on GETs.</dd>
50
51 <dt>Compression</dt>
52 <dd>Handles both 'compress' and 'gzip' types of compression.</dd>
53
54 <dt>Lost update support</dt>
55 <dd>Automatically adds back ETags into PUT requests to resources
56 we have already cached. This implements Section 3.2 of
57 <a href="http://www.w3.org/1999/04/Editing/#Table">Detecting the Lost Update Problem Using Unreserved Checkout</a></dd>
58
59 <dt>Unit Tested</dt>
60 <dd>A large and growing set of unit tests.</dd>
61
62 </dl>
63
64<h2>Usage</h2>
65
66<p>A simple retrieval:</p>
67
68<pre><code> import httplib2
69 h = httplib2.Http(".cache")
70 (resp_headers, content) = h.request("http://example.org/", "GET")
71</code></pre>
72
73<p>The 'content' is the content retrieved from the URL.
74The content is already decompressed or unzipped if necessary.
75</p>
76
77<p>To PUT some content to a server that uses SSL
78and Basic authentication:</p>
79
80<pre><code> import httplib2
81 h = httplib2.Http(".cache")
82 h.add_credentals('name', 'password')
83 (resp, content) = h.request("https://example.org/chapter/2",
84 "PUT", body="This is text",
85 headers={'content-type':'text/plain'} )
86</code></pre>
87
88<p>Use the Cache-Control: header to control
89 how the caching operates.</p>
90
91<pre><code> import httplib2
92 h = httplib2.Http(".cache")
93 (resp, content) = h.request("http://bitworking.org/", "GET")
94 ...
95 (resp, content) = h.request("http://bitworking.org/", "GET",
96 headers={'cache-control':'no-cache'})
97</code></pre>
98
99<p>The first request will be cached and since this is a request to
100bitworking.org it will be set to be cached for two hours, because
101that is how I have my server configured.
102Any subsequent GET to that URI will return the value from the
103on-disk cache and no request will be made to the server.
104You can use the Cache-Control: header to change the caches behavior and
105in this example the second request adds the Cache-Control: header with a value
106of 'no-cache' which tells the library that the cached copy
107must not be used when handling this request.
108</p>
109
110<h2>Requirements</h2>
111
jcgregorio1eed40f2006-02-15 18:56:46 +0000112<p>Requires Python 2.3 or later. Does not require
jcgregorio2d66d4f2006-02-07 05:34:14 +0000113any libraries beyond what is found in the core library.</p>
114
jcgregorio1eed40f2006-02-15 18:56:46 +0000115<h2>Download/Installation</h2>
116
117<p>The httplib2 module is shipped as a distutils package. To install
118the library, first unpack the distribution archive, and issue the following
119command:</p>
120
121<pre><code>$ python setup.py install</code></pre>
122
123<p><a href="dist">Download the distribution archives from here</a>. </p>
124
125<p> <a href="test">The resources used in the unit test cases</a>
126 are available also. More documentation on them will be forthcoming.</p>
127
jcgregorio2d66d4f2006-02-07 05:34:14 +0000128<h2>To Do</h2>
129
130<p>This module is not perfect and needs the following:</p>
131<ul>
132 <li>Support for Proxies</li>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000133 <li>A pluggable store for the cache. Right now the store is just flat files in a directory.
134 I would like to have plugins that allow keeping the cache in Berkeley DB, Squid, MySQL, etc.</li>
135 <li>More unit tests</li>
136</ul>
137
138<h2>Project Goal</h2>
139
140<p>To become a worthy addition to the Pyhton core library.</p>
141
142<h2>Additional Information</h2>
143
144<p>
145 <dl>
146 <dt>Author</dt>
147 <dd>Joe Gregorio</dd>
148
149 <dt>License</dt>
150 <dd>MIT</dd>
151
152 <dt>Contributors</dt>
153 <dd>(Your name here)</dd>
154 </dl>
155</p>
156
jcgregorio1eed40f2006-02-15 18:56:46 +0000157 <p style="font-size: small">This page last updated on: $LastChangedDate$.</p>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000158
159 </div>
160 </div>
161 <!--#include virtual="footer.html" -->
162 </div>
163</body>
164
165</html>