From e3a6a07e2f69303241e5f8d015d5c1299c4b988f Mon Sep 17 00:00:00 2001 From: grisha Date: Tue, 17 Sep 2002 03:37:23 +0000 Subject: [PATCH] Figured out the issue of content-length being wrong when filter is invoked more than once in a request. --- Doc/modpython4.tex | 12 +++++++++++- lib/python/mod_python/apache.py | 6 +++--- src/filterobject.c | 12 +++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Doc/modpython4.tex b/Doc/modpython4.tex index 56e27049..d2841512 100644 --- a/Doc/modpython4.tex +++ b/Doc/modpython4.tex @@ -187,6 +187,9 @@ \section{Overview of a Filter Handler\label{pyapi-filter}} writing and reading should be done via the filter's object read and write methods. +Filters need to be closed when a read operation returns None +(indicating End-Of-Stream). + Similarly to a phase handler, a filter handler must return one of the status return codes. @@ -210,7 +213,14 @@ \section{Overview of a Filter Handler\label{pyapi-filter}} def outputfilter(filter): - filter.write(filter.read().upper()) + s = filter.read() + while s: + filter.write(s.upper()) + s = filter.read() + + if s is None: + filter.close() + return apache.OK \end{verbatim} diff --git a/lib/python/mod_python/apache.py b/lib/python/mod_python/apache.py index 1bf5ea98..c089150a 100755 --- a/lib/python/mod_python/apache.py +++ b/lib/python/mod_python/apache.py @@ -224,11 +224,11 @@ def FilterDispatch(self, filter): else: result = object(filter) - # always close the filter - filter.close() + # always flush the filter + filter.flush() assert (type(result) == type(int())), \ - "Filter '%s' returned invalid return code." % filter.handler + "Filter '%s' returned invalid return code: %s" % (filter.handler, `result`) except SERVER_RETURN, value: # SERVER_RETURN indicates a non-local abort from below diff --git a/src/filterobject.c b/src/filterobject.c index 22735b92..52a85f8c 100644 --- a/src/filterobject.c +++ b/src/filterobject.c @@ -57,7 +57,7 @@ * * filterobject.c * - * $Id: filterobject.c,v 1.12 2002/09/16 21:33:39 grisha Exp $ + * $Id: filterobject.c,v 1.13 2002/09/17 03:37:23 grisha Exp $ * * See accompanying documentation and source code comments * for details. @@ -170,10 +170,12 @@ static PyObject *_filter_read(filterobject *self, PyObject *args, int readline) b = APR_BRIGADE_FIRST(self->bb_in); - /* reached eos on previous invocation? */ - if (APR_BUCKET_IS_EOS(b) || b == APR_BRIGADE_SENTINEL(self->bb_in)) { - if (b != APR_BRIGADE_SENTINEL(self->bb_in)) - apr_bucket_delete(b); + if (b == APR_BRIGADE_SENTINEL(self->bb_in)) + return PyString_FromString(""); + + /* reached eos ? */ + if (APR_BUCKET_IS_EOS(b)) { + apr_bucket_delete(b); Py_INCREF(Py_None); return Py_None; }