blob: 16591fb732889c5bcf830eb095545399dc1ded1e [file] [log] [blame]
Joe Gregorioc5c5a372010-09-22 11:42:32 -04001# Copyright 2010 Google Inc. All Rights Reserved.
2
3"""One-line documentation for http module.
4
5A detailed description of http.
6"""
7
8__author__ = 'jcgregorio@google.com (Joe Gregorio)'
9
10
11class HttpRequest(object):
12 """Encapsulate an HTTP request.
13 """
14
15 def __init__(self, http, uri, method="GET", body=None, headers=None, postproc=None):
16 self.uri = uri
17 self.method = method
18 self.body = body
19 self.headers = headers or {}
20 self.http = http
21 self.postproc = postproc
22
23 def execute(self, http=None):
24 """Execute the request.
25
26 If an http object is passed in it is used instead of the
27 httplib2.Http object that the request was constructed with.
28 """
29 if http is None:
30 http = self.http
31 resp, content = http.request(self.uri, self.method,
32 body=self.body,
33 headers=self.headers)
34 return self.postproc(resp, content)