wsgi, ajax, and multiple requests

Frank Millman frank at chagford.com
Wed Feb 9 07:31:46 EST 2011


Hi all

I have a question about wsgi.

As far as I can tell from the spec and from the reference implementation, 
wsgi requires that each request from the client is responded to by one or 
more headers, followed by the response body. It is then ready to handle the 
next request.

99% of the time this is fine, but I have a situation where I need to vary 
this, and I cannot see how to do it. Here is the scenario.

I am dabbling with writing an ajax-style app. On occasion, I want to send 
more than one message from the client to the server. It is important that 
the server processes the messages in the same order that they are generated. 
I have found that the Safari browser does not always send them in the 
correct sequence.

I found an article on the subject -

http://www.sitepen.com/blog/2009/02/27/deterministic-clientserver-interaction/

It explains that you can never guarantee that the messages will arrive in 
the same order, with *any* browser. Maybe I was lucky with the other ones. 
It goes on to say that, if the order is important, you must include a header 
with a sequential counter, and the server must check the sequence. If 
received out of sequence, it must queue the one received, wait for the 
correct one, and then process them both in the correct order.

So the question is, how can I achieve this with wsgi? If I detect that I 
have received a request out of sequence, I can queue the request, and send 
an empty response. When I receive the correct request, I can process it, 
call start_response(), and return the response body, but I cannot figure out 
how to get back to process the queued request.

Any advice will be much appreciated.

Frank Millman





More information about the Python-list mailing list