On 15 November 2010 14:23, Carl Nobile <[email protected]> wrote: > Opps, Graham you are right the iterator which I mentioned wouldn't be > needed if all it did was create a list that got sent out. However, the > PEP0333 also does have an example of an iterator in it done correctly. > > How is not setting the Content-Length not taking advantage of HTTP/1.1 > chunk encoding? Wouldn't, and this is an assumption, apache or > whatever the server is add the chunk-size field to the header as > explained in RFC2616 Chapter 3.6.1?
It is not a requirement of WSGI that an underlying WSGI server take lack of a content length to mean it should use HTTP/1.1 chunked encoding. A WSGI server could implement HTTP/1.0 and so not use it, with expectation that client will read until socket is closed. A client could also say it only supports HTTP/1.0 and so technically the server shouldn't be using HTTP/1.1 features in a response. So, up to the WSGI server and thus you could need to check what specific implementations do. In the case of Apache/mod_wsgi, HTTP/1.1 chunked encoding would be used on response if no Content-Length response header so long as client is HTTP/1.1 and server configuration doesn't override what the client says and force it to use HTTP/1.0 using BrowserMatch and downgrade-1.0 option. Note that Apache/mod_wsgi no longer performs auto Content-Length generation for case of array of single text string being returned. This is because it breaks for HEAD requests. See: http://blog.dscpl.com.au/2009/10/wsgi-issues-with-http-head-requests.html Graham > ~Carl > > On Sun, Nov 14, 2010 at 9:50 PM, Graham Dumpleton > <[email protected]> wrote: >> On 15 November 2010 12:37, Carl Nobile <[email protected]> wrote: >>> This is really a WSGI question which is explained in the PEP 0333 spec >>> below. >>> >>> http://www.python.org/dev/peps/pep-0333/ >>> >>> What you want to do uses the HTTP chunk response. >> >> Technically it is wrong to refer to it as chunked response as WSGI >> specification doesn't deal with issue of chunked responses in as much >> as that term is used in HTTP. >> >> Anyway, the short of it is that you should simply not set a >> Content-Length response header. >> >> Rather than return an array of strings, you would use yield to return >> successive blocks of data for the response. Alternatively, you write a >> custom iterable with appropriate next() method for returning next >> block of data. In other words, use a generator like object. >> >> You can find a lot of articles on WSGI referenced from: >> >> http://www.wsgi.org/wsgi/Learn_WSGI >> >> Graham >> >>> The spec shows how to write an iterator that creates a list that would >>> be sent out. >>> >>> ~Carl >>> >>> On Sun, Nov 14, 2010 at 8:29 PM, Gelonida <[email protected]> wrote: >>>> Hi, >>>> >>>> I'd like to write an application, which generates https output of an >>>> unkown length >>>> >>>> It will basically be a python function >>>> yielding a number of strings. >>>> >>>> >>>> What do I have to return as Content-Length ??? >>>> >>>> 0, >>>> -1, >>>> not send the Content-Length Header? >>>> >>>> something else? >>>> >>>> >>>> Currently I have a wrapper function collecting the strings, calculation >>>> their size and returning a list of all entries. >>>> >>>> Is ths really the only solution? >>>> >>>> >>>> thanks in advance for suggestions / ideas >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google Groups >>>> "modwsgi" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]. >>>> For more options, visit this group at >>>> http://groups.google.com/group/modwsgi?hl=en. >>>> >>>> >>> >>> >>> >>> -- >>> ------------------------------------------------------------------------------- >>> Carl J. Nobile (Software Engineer) >>> [email protected] >>> ------------------------------------------------------------------------------- >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "modwsgi" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/modwsgi?hl=en. >>> >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "modwsgi" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/modwsgi?hl=en. >> >> > > > > -- > ------------------------------------------------------------------------------- > Carl J. Nobile (Software Engineer) > [email protected] > ------------------------------------------------------------------------------- > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/modwsgi?hl=en. > > -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
