1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - FastCGI Request Implementation for fastcgi and Apache
6
@copyright: 2001-2003 Juergen Hermann <jh@web.de>,
7
2003-2006 MoinMoin:ThomasWaldmann
8
@license: GNU GPL, see COPYING for details.
10
from MoinMoin import log
11
logging = log.getLogger(__name__)
13
from MoinMoin.request import RequestBase, RemoteClosedConnection
15
class Request(RequestBase):
16
""" specialized on FastCGI requests """
18
def __init__(self, fcgRequest, env, form, properties={}):
19
""" Initializes variables from FastCGI environment and saves
20
FastCGI request and form for further use.
22
@param fcgRequest: the FastCGI request instance.
23
@param env: environment passed by FastCGI.
24
@param form: FieldStorage passed by FastCGI.
27
self.fcgreq = fcgRequest
30
self._setup_vars_from_std_env(env)
31
RequestBase.__init__(self, properties)
33
except Exception, err:
36
def _setup_args_from_cgi_form(self):
37
""" Override to use FastCGI form """
38
# thfcgi used keep_blank_values=1 internally for fcgform
39
return RequestBase._setup_args_from_cgi_form(self, self.fcgform)
42
""" Read from input stream. """
44
logging.warning("calling request.read(None) might block")
45
return self.fcgreq.stdin.read()
47
return self.fcgreq.stdin.read(n)
49
def write(self, *data):
50
""" Write to output stream. """
51
data = self.encode(data)
53
self.fcgreq.out.write(data)
55
raise RemoteClosedConnection()
57
def send_file(self, fileobj, bufsize=8192, do_flush=True):
58
# as thfcgi buffers everything we write until we do a flush, we use
59
# do_flush=True as default here (otherwise the sending of big file
60
# attachments would consume lots of memory)
61
return RequestBase.send_file(self, fileobj, bufsize, do_flush)
64
""" Flush output stream. """
65
self.fcgreq.flush_out()
68
""" Call finish method of FastCGI request to finish handling of this request. """
69
RequestBase.finish(self)
72
def _emit_http_headers(self, headers):
73
""" private method to send out preprocessed list of HTTP headers """
74
for header in headers:
75
self.write("%s\r\n" % header)