blob: 25d646e5c70674d5bccd24c763301fa89e33e169 [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
Joe Gregorio00cf1d92010-09-27 09:22:03 -040015 def __init__(self, http, uri, method="GET", body=None, headers=None,
16 postproc=None):
Joe Gregorioc5c5a372010-09-22 11:42:32 -040017 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)