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