Python 7.0pl5 Electronic Accessory User Manual


 
Slow HTTP Clients
101
password = self.field("password")
if self.authenticateUser(user,password):
self.sendResponse(netsvc.REDIRECT_TEMPORARY)
self.sendHeader("Location",self.serverRoot())
self.endHeaders()
self.endContent()
else:
self.sendError(400)
else:
self.sendError(400)
def authenticateUser(self,user,password):
# ...
The existance of a field can be determined by calling the "containsField()" member function.
The member function "field()" can then be called to retrieve the value for the field. All fields which
have been set can be obtained as a dictionary using the "fields()" member function.
Slow HTTP Clients
The HTTP servlet framework does not use multithreading but is layered on top of an event system.
This fact means that it is not possible for a HTTP servlet to block, as doing so would block the whole
process and stop anything else from running. For this reason, a HTTP servlet does not have direct ac-
cess to the socket connection associated with a HTTP client. Instead, a HTTP servlet in sending data
back to a HTTP client is effectively queueing the data for deliverly.
If the HTTP client is slow in reading data from a socket connection, the server side of the socket con-
nection could effectively block. The underlying framework used to manage a socket connection will
detect this, and will only send data over a socket connection when such a condition would not occur.
A consequence of the queuing mechanism however is that any data will first be added to a queue and
will only be sent after the servlet has returned.
For a small response this would not be a problem, but if the content associated with a response is large,
the size of the process would grow dramatically if all data is queued at once. To avoid this, it is impor-
tant that if sending large responses that they be sent in parts. Further, a HTTP servlet should suspend
sending of further data when the socket connection would block, as this would again only serve to grow
the amount of queued data and thus the size of the process.
To monitor changes in the state of the socket connection, a HTTP servlet should call the member func-
tion "monitorCongestion()", passing a callback function. The callback function supplied will
be called when writing data to a socket connection would effectively block and also subsequently when
the socket has cleared. These changes in state can be used to suspend and subsequently resume sending
of data.
class TestServlet(netsvc.FormServlet):
def __init__(self,session):
netsvc.FormServlet.__init__(self,session)