[Web-SIG] WSGI: read method

Robert Brewer fumanchu at amor.org
Fri Sep 8 20:46:52 CEST 2006


Ian Bicking wrote:
> An issue I just realized (as Robert was bringing up these things),
> is that I would like to be able to give input streams that don't
> have a known length.  In particular, I want to be able to do this:
> 
> input = environ['wsgi.input']
> if hasattr(input, 'json_request'):
>      request = input.json_request
> else:
>      if 'CONTENT_LENGTH' in environ:
>          raw_request = input.read(int(environ['CONTENT_LENGTH']))
>      else:
>          raw_request = input.read()
>      request = simplejson.loads(raw_request)
> 
> The idea is that the request body won't be serialized unless necessary,
> so internal requests (JSON, XMLRPC, etc) can avoid any serialization,
> while the WSGI app can deal with both these cases and normal 
> string-based requests.  But I can't set CONTENT_LENGTH during these 
> internal requests, because I'd need to figure out how long the 
> serialized request body was, and that would require actually serializing it.
> 
> In the end it doesn't matter a whole lot, because almost no 
> intermediaries every look at wsgi.input, though if WSGI apps expecting a 
> JSON request but not aware of .json_request get one of these requests, 
> it is likely they will fail.
> 
> Hmm... I could also set CONTENT_LENGTH='1', and make .read(1) return the 
> actual entire body, totally ignoring the size argument.  Or make it 
> '99999', or whatever.  That seems bad-clever, but maybe most workable 
> with PEP 333?

I'm getting lost on the phrase "internal request"--what do you mean by that?


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/web-sig/attachments/20060908/3f43b134/attachment.htm 


More information about the Web-SIG mailing list