<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>RE: [Web-SIG] WSGI: read method</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

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

</BODY>
</HTML>