[Web-SIG] environ["wsgi.input"].read()

James Y Knight foom at fuhm.net
Fri Jan 25 18:20:57 CET 2008


On Jan 25, 2008, at 10:04 AM, Brian Smith wrote:
> 1. PEP 333 doesn't indicate that the size parameter for the read()  
> method is optional. Is it optional or required? If it is optional,  
> is the default value -1?

The spec says it's required (by virtue of not saying it's optional)

> 2. What are the semantics of environ["wsgi.input"].read(-1) when  
> Content-Length is provided? Is it guaranteed to return the entire  
> request entity, up to at most <Content-Length> bytes?

There is no such guarantee written in the spec, so you should assume  
it's not guaranteed.

> 3. What are the semantics of environ["wsgi.input"].read(-1) when the  
> response has no Content-Length? Can environ["wsgi.input"].read(-1)  
> be used (as the only available mechanism) to read a chunked response  
> entity?

The CGI specification, and thus WSGI by implication, doesn't allow for  
chunked input. The CONTENT_LENGTH environment key is a required value  
if there is content. The only correct thing for a gateway to do is to  
reject a request with chunked input.

> Putting all this together, are these two programs correct?:
>
> def application(environ, start_response):
> 	start_response("200 OK", [])
> 	yield environ["wsgi.input"].read()
>
> def application(environ, start_response):
> 	start_response("200 OK", [])
> 	yield environ["wsgi.input"].read(-1)

No, they rely on non-standard behavior.

> This is another issue where there is a lot of variance between  
> gateways, where I think a clarification in the specification is  
> needed.


The spec is fairly clear as to what you can rely on here. Additional  
behavior may of course be implemented in some gateway, but it's going  
to be non-portable.

James


More information about the Web-SIG mailing list