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