blob: 011efb993857c324a2a9d183488fed41e1fda1e2 [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
112<p>Requires Python 2.4 or later. Does not require
113any libraries beyond what is found in the core library.</p>
114
115<h2>To Do</h2>
116
117<p>This module is not perfect and needs the following:</p>
118<ul>
119 <li>Support for Proxies</li>
120 <li>A setup.py script</li>
121 <li>A pluggable store for the cache. Right now the store is just flat files in a directory.
122 I would like to have plugins that allow keeping the cache in Berkeley DB, Squid, MySQL, etc.</li>
123 <li>More unit tests</li>
124</ul>
125
126<h2>Project Goal</h2>
127
128<p>To become a worthy addition to the Pyhton core library.</p>
129
130<h2>Additional Information</h2>
131
132<p>
133 <dl>
134 <dt>Author</dt>
135 <dd>Joe Gregorio</dd>
136
137 <dt>License</dt>
138 <dd>MIT</dd>
139
140 <dt>Contributors</dt>
141 <dd>(Your name here)</dd>
142 </dl>
143</p>
144
145<h2>Download</h2>
146
147<p><a href="httplib2.py.txt">httplib2.py</a> - The uncompressed source code of the single file
148that constitutes this module.
149</p>
150
151<p> <a href="httplib2test.py.txt">httplibi2test.py</a> - The uncompressed source code of the single file
152that constitutes this modules unit test suite.
153</p>
154
155<p> <a href="test">test</a> - The resources used in the unit test cases. </p>
156
157<h2>Revision History</h2>
158 <dl>
159 <dt>0.1</dt>
160 <dd>Initial Release.</dd>
161 </dl>
162
163<p>This page last updated on: $LastChangedDate$.</p>
164
165 </div>
166 </div>
167 <!--#include virtual="footer.html" -->
168 </div>
169</body>
170
171</html>