mod_wsgi currently only allows the WSGIErrorOverride directive to be used
when in daemon mode. It is sometimes nice to use a single set of apache
error-handling directives with a non-daemon mode mod_wsgi. This patch
allows the ErrorOverride directive to apply when running mod_wsgi in
non-daemon mode if the WSGI application does not actually emit any data
itself.
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/modwsgi/-/ATE678lmS7IJ.
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.
diff -urNad mod_wsgi~/mod_wsgi.c mod_wsgi/mod_wsgi.c
--- mod_wsgi~/mod_wsgi.c 2011-09-26 14:48:50.000000000 -0700
+++ mod_wsgi/mod_wsgi.c 2011-09-26 14:49:20.348519029 -0700
@@ -3841,6 +3841,11 @@
self->sequence = PyEval_CallObject(object, args);
if (self->sequence != NULL) {
+ /* Store whether or not the iterator had any contents; we'll use
+ * this in conjunction with WSGIErrorOverride to determine whether
+ * to let apache serve an error document itself.
+ */
+ int saw_output = 0;
if (!Adapter_process_file_wrapper(self)) {
int aborted = 0;
@@ -3850,6 +3855,7 @@
PyObject *item = NULL;
while ((item = PyIter_Next(iterator))) {
+ saw_output = 1;
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(item)) {
PyObject *latin_item;
@@ -3904,6 +3910,19 @@
Py_XDECREF(iterator);
}
+ if (self->config->error_override && !saw_output && ap_is_HTTP_ERROR(self->r->status)) {
+ int status = self->r->status;
+
+ self->r->status = HTTP_OK;
+ self->r->status_line = NULL;
+
+ Py_DECREF(self->sequence);
+ self->sequence = NULL;
+
+ return status;
+ }
+
+
if (PyErr_Occurred()) {
/*
* Response content has already been sent, so cannot