quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sander Striker <stri...@apache.org>
Subject [PATCH] Expose ap_meets_conditions()
Date Mon, 18 Apr 2005 17:20:57 GMT
Hi,

Small patch to expose ap_meets_conditions().  Documentation could use
some review.  Also note that I haven't run the documentation through
a validator/generator...

Sander


Log:
Expose ap_meets_conditions() to allow for easier checking of conditional
headers.  Primarily meant to facilitate caching.

* src/requestobject.c

  (req_meets_conditions): New function.  Simple wrapper around
   ap_meets_conditions().


* Doc/modpython4.tex

  (meets_conditions): New documentation blurb.

Index: src/requestobject.c
===================================================================
--- src/requestobject.c	(revision 161666)
+++ src/requestobject.c	(working copy)
@@ -419,6 +419,17 @@
 }
 
 /**
+ ** request.meets_conditions(req self)
+ **
+ *  ap_meets_conditions wrapper
+ */
+
+static PyObject * req_meets_conditions(requestobject *self)
+{
+    return PyInt_FromLong(ap_meets_conditions(self->request_rec));
+}
+
+/**
  ** request.read(request self, int bytes)
  **
  *     Reads stuff like POST requests from the client
@@ -951,6 +962,7 @@
     {"get_options",           (PyCFunction) req_get_options,           METH_NOARGS},
     {"internal_redirect",     (PyCFunction) req_internal_redirect,     METH_VARARGS},
     {"log_error",             (PyCFunction) req_log_error,             METH_VARARGS},
+    {"meets_conditions",      (PyCFunction) req_meets_conditions,      METH_NOARGS},
     {"read",                  (PyCFunction) req_read,                  METH_VARARGS},
     {"readline",              (PyCFunction) req_readline,              METH_VARARGS},
     {"readlines",             (PyCFunction) req_readlines,             METH_VARARGS},
Index: Doc/modpython4.tex
===================================================================
--- Doc/modpython4.tex	(revision 161666)
+++ Doc/modpython4.tex	(working copy)
@@ -656,6 +656,30 @@
   use the \function{apache.log_error} function.
 \end{methoddesc}
 
+\begin{methoddesc}[request]{meets_conditions}{}
+  Calls the Apache \cfunction{ap_meets_conditions()} function which
+  returns a status code.  If \var{status} is \constant{apache.OK}, generate
+  the content of the response normally.  If not, simply return \var{status}.
+  Note that \member{req.headers_out} should be set prior to calling this
+  function.  The same goes for \member{req.status} if the status differs
+  from \constant{apache.OK}.
+
+  Example:
+  \begin{verbatim}
+...
+r.headers_out['ETag'] = "1130794f-3774-4584-a4ea-0ab19e684268"
+r.headers_out['Last-Modified'] = 'Wed, 23 Feb 2005 00:00:00 GMT'
+r.headers_out['Expires'] = 'Mon, 18 Apr 2005 17:30:00 GMT'
+
+status = r.meets_conditions()
+if status != apache.OK:
+  return status
+
+... do expensive generation of the response content ... 
+  \end{verbatim}
+
+\end{methoddesc}
+
 \begin{methoddesc}[request]{requires}{}
 
   Returns a tuple of strings of arguments to \code{require} directive.

Mime
View raw message