Skip to content

Commit

Permalink
Figured out the issue of content-length being wrong when filter is in…
Browse files Browse the repository at this point in the history
…voked

more than once in a request.
  • Loading branch information
grisha committed Sep 17, 2002
1 parent ab3f795 commit e3a6a07
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
12 changes: 11 additions & 1 deletion Doc/modpython4.tex
Expand Up @@ -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.

Expand All @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions lib/python/mod_python/apache.py
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/filterobject.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e3a6a07

Please sign in to comment.