Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes
MoinMoin.support.flup.server.ajp_base.Request Class Reference

List of all members.

Public Member Functions

def __init__
def run
def setMethod
def setProtocol
def setRequestURI
def setRemoteAddr
def setRemoteHost
def setServerName
def setServerPort
def setIsSSL
def addHeader
def addAttribute
def startResponse
def write

Public Attributes

 environ
 input
 logger

Private Attributes

 _conn
 _headersSent

Static Private Attributes

int _maxWrite = 8192

Detailed Description

A Request object. A more fitting name would probably be Transaction, but
it's named Request to mirror my FastCGI driver. :) This object
encapsulates all the data about the HTTP request and allows the handler
to send a response.

The only attributes/methods that the handler should concern itself
with are: environ, input, startResponse(), and write().

Definition at line 455 of file ajp_base.py.


Constructor & Destructor Documentation

Definition at line 468 of file ajp_base.py.

00468 
00469     def __init__(self, conn):
00470         self._conn = conn
00471 
00472         self.environ = {}
00473         self.input = InputStream(conn)
00474 
00475         self._headersSent = False
00476 
00477         self.logger = logging.getLogger(LoggerName)


Member Function Documentation

def MoinMoin.support.flup.server.ajp_base.Request.addAttribute (   self,
  name,
  value 
)

Definition at line 544 of file ajp_base.py.

00544 
00545     def addAttribute(self, name, value):
00546         self.environ[name] = value

def MoinMoin.support.flup.server.ajp_base.Request.addHeader (   self,
  name,
  value 
)

Definition at line 534 of file ajp_base.py.

00534 
00535     def addHeader(self, name, value):
00536         name = name.replace('-', '_').upper()
00537         if name in ('CONTENT_TYPE', 'CONTENT_LENGTH'):
00538             self.environ[name] = value
00539             if name == 'CONTENT_LENGTH':
00540                 length = int(value)
00541                 self.input.setDataLength(length)
00542         else:
00543             self.environ['HTTP_'+name] = value

Definition at line 478 of file ajp_base.py.

00478 
00479     def run(self):
00480         self.logger.info('%s %s',
00481                          self.environ['REQUEST_METHOD'],
00482                          self.environ['REQUEST_URI'])
00483 
00484         start = datetime.datetime.now()
00485 
00486         try:
00487             self._conn.server.handler(self)
00488         except:
00489             self.logger.exception('Exception caught from handler')
00490             if not self._headersSent:
00491                 self._conn.server.error(self)
00492 
00493         end = datetime.datetime.now()
00494 
00495         # Notify server of end of response (reuse flag is set to true).
00496         pkt = Packet()
00497         pkt.data = PKTTYPE_END_RESPONSE + '\x01'
00498         self._conn.writePacket(pkt)
00499 
00500         handlerTime = end - start
00501         self.logger.debug('%s %s done (%.3f secs)',
00502                           self.environ['REQUEST_METHOD'],
00503                           self.environ['REQUEST_URI'],
00504                           handlerTime.seconds +
00505                           handlerTime.microseconds / 1000000.0)

Definition at line 530 of file ajp_base.py.

00530 
00531     def setIsSSL(self, value):
00532         if value:
00533             self.environ['HTTPS'] = 'on'

Definition at line 509 of file ajp_base.py.

00509 
00510     def setMethod(self, value):
00511         self.environ['REQUEST_METHOD'] = value

Definition at line 512 of file ajp_base.py.

00512 
00513     def setProtocol(self, value):
00514         self.environ['SERVER_PROTOCOL'] = value

Definition at line 518 of file ajp_base.py.

00518 
00519     def setRemoteAddr(self, value):
00520         self.environ['REMOTE_ADDR'] = value

Definition at line 521 of file ajp_base.py.

00521 
00522     def setRemoteHost(self, value):
00523         self.environ['REMOTE_HOST'] = value

Definition at line 515 of file ajp_base.py.

00515 
00516     def setRequestURI(self, value):
00517         self.environ['REQUEST_URI'] = value

Definition at line 524 of file ajp_base.py.

00524 
00525     def setServerName(self, value):
00526         self.environ['SERVER_NAME'] = value

Definition at line 527 of file ajp_base.py.

00527 
00528     def setServerPort(self, value):
00529         self.environ['SERVER_PORT'] = str(value)

def MoinMoin.support.flup.server.ajp_base.Request.startResponse (   self,
  statusCode,
  statusMsg,
  headers 
)
Begin the HTTP response. This must only be called once and it
must be called before any calls to write().

statusCode is the integer status code (e.g. 200). statusMsg
is the associated reason message (e.g.'OK'). headers is a list
of 2-tuples - header name/value pairs. (Both header name and value
must be strings.)

Definition at line 549 of file ajp_base.py.

00549 
00550     def startResponse(self, statusCode, statusMsg, headers):
00551         """
00552         Begin the HTTP response. This must only be called once and it
00553         must be called before any calls to write().
00554 
00555         statusCode is the integer status code (e.g. 200). statusMsg
00556         is the associated reason message (e.g.'OK'). headers is a list
00557         of 2-tuples - header name/value pairs. (Both header name and value
00558         must be strings.)
00559         """
00560         assert not self._headersSent, 'Headers already sent!'
00561 
00562         pkt = Packet()
00563         pkt.data = PKTTYPE_SEND_HEADERS + \
00564                    struct.pack('>H', statusCode) + \
00565                    encodeString(statusMsg) + \
00566                    struct.pack('>H', len(headers)) + \
00567                    ''.join([encodeResponseHeader(name, value)
00568                             for name,value in headers])
00569 
00570         self._conn.writePacket(pkt)
00571 
00572         self._headersSent = True

Here is the call graph for this function:

Write data (which comprises the response body). Note that due to
restrictions on AJP packet size, we limit our writes to 8185 bytes
each packet.

Definition at line 573 of file ajp_base.py.

00573 
00574     def write(self, data):
00575         """
00576         Write data (which comprises the response body). Note that due to
00577         restrictions on AJP packet size, we limit our writes to 8185 bytes
00578         each packet.
00579         """
00580         assert self._headersSent, 'Headers must be sent first!'
00581 
00582         bytesLeft = len(data)
00583         while bytesLeft:
00584             toWrite = min(bytesLeft, self._maxWrite)
00585 
00586             pkt = Packet()
00587             pkt.data = PKTTYPE_SEND_BODY + \
00588                        struct.pack('>H', toWrite) + \
00589                        data[:toWrite] + '\x00' # Undocumented
00590             self._conn.writePacket(pkt)
00591 
00592             data = data[toWrite:]
00593             bytesLeft -= toWrite

Here is the caller graph for this function:


Member Data Documentation

Definition at line 469 of file ajp_base.py.

Definition at line 474 of file ajp_base.py.

Definition at line 466 of file ajp_base.py.

Definition at line 471 of file ajp_base.py.

Definition at line 472 of file ajp_base.py.

Definition at line 476 of file ajp_base.py.


The documentation for this class was generated from the following file: