# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-from urllib2 import HTTPRedirectHandler
+from urllib2 import HTTPRedirectHandler, BaseHandler
from urllib2 import HTTPError
def http_error_302(self, req, fp, code, msg, hdrs):
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
+
+
+class HTTPDebugHandler(BaseHandler):
+
+ def http_request(self, req):
+ print req.get_method(), req.get_full_url()
+ for field in req.header_items():
+ print "%s: %s" % field
+ return req
+
+ def http_response(self, req, response):
+ print "%d %s" % (response.code, response.msg)
+ print response.info()
+ return response