Title: RE: [Web-SIG] WSGI: read method

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
[EMAIL PROTECTED]

_______________________________________________
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: 
http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com

Reply via email to