Return-Path: Delivered-To: apmail-httpd-modules-dev-archive@locus.apache.org Received: (qmail 11175 invoked from network); 6 Sep 2007 13:10:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Sep 2007 13:10:03 -0000 Received: (qmail 12178 invoked by uid 500); 6 Sep 2007 13:09:46 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 12116 invoked by uid 500); 6 Sep 2007 13:09:45 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 12087 invoked by uid 99); 6 Sep 2007 13:09:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2007 06:09:45 -0700 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [194.36.240.52] (HELO extmx1.mail.eu.nomura.com) (194.36.240.52) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2007 13:09:40 +0000 Received: from mailrouter1.uk.nomura.com (mailrouter3.mail.eu.nomura.com [147.201.184.141]) by extmx1.mail.eu.nomura.com (8.13.6/8.12.10) with ESMTP id l86D9D1M017782 for ; Thu, 6 Sep 2007 14:09:14 +0100 (BST) Received: from uw0425.uk.nomura.com (uw0425 [147.201.158.200]) by mailrouter1.uk.nomura.com (8.13.6/8.12.10) with ESMTP id l86D9Atv007150 for ; Thu, 6 Sep 2007 14:09:10 +0100 (BST) Received: (from grinterj@localhost) by uw0425.uk.nomura.com (8.11.7p1+Sun/8.9.3) id l86D9AQ18885 for modules-dev@httpd.apache.org; Thu, 6 Sep 2007 14:09:10 +0100 (BST) Date: Thu, 6 Sep 2007 14:09:10 +0100 From: James R Grinter To: modules-dev@httpd.apache.org Subject: influencing mod_proxy via request_status hook Message-ID: <20070906130909.GF10920@uw0425.uk.nomura.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-Ngb-Disclaimer: None X-Proofpoint-Virus-Version: vendor=nai engine=5.1.00 definitions=5113 signatures=317418 X-Proofpoint-Spam-Details: rule=eudefault_notspam policy=eudefault score=0 mlx=0 adultscore=0 adjust=0 reason=mlx engine=3.1.0-0708230000 definitions=main-0709060013 X-Virus-Checked: Checked by ClamAV on apache.org (If this is better directed at another Apache httpd tech list, please let me know.) I'm trying to modify the behaviour of mod_proxy via its optional request_status hook. I want Apache to use mod_cache's local copy of a file if it can't verify it with the remote, reverse-proxied server (server down, or not responding, etc.) The VirtualHost's Cache and Proxy is configured like this: CacheRoot /var/cache CacheEnable disk / ProxyRequests Off ProxyVia On Order allow,deny Allow from all ProxyPass /path http://realserver/path ProxyPassReverse /path http://realserver/path ProxyRemote * http://proxyserver:8080/ The requests are just GETs. "realserver" is the remote server hostname, and "proxyserver" is the in-between proxy server that the request must go through (just for that added extra complication.) I've successfully got my own module being called via the request_status hook every time. But I can't seem to then make mod_proxy act as if it had got a 304 HTTP_NOT_MODIFIED from the remote server (which is what it would normally get if the remote server were to respond) and so use the locally cached copy of the file. Whenever the remote server is down, I get the 5xx error from the in-between proxy. If I take the in-between proxy down, I get an error from within Apache. Here's my module's code: #include #include #include #include static int proxy_request_status_handler ( int *status, request_rec *r ) { ap_log_error(APLOG_MARK,APLOG_ERR,OK,NULL,"request_status hook called (%s): %d (%d)", r->server->server_hostname, *status, r->status); if ( r->status >= HTTP_INTERNAL_SERVER_ERROR ) { *status = DECLINED; ap_log_error(APLOG_MARK,APLOG_ERR,OK,NULL,"request_status hook declined: %d (%d)", *status, r->status); } } static void my_register_hooks(apr_pool_t *p) { APR_OPTIONAL_HOOK(proxy, request_status, proxy_request_status_handler, NULL, NULL, APR_HOOK_MIDDLE ); } module AP_MODULE_DECLARE_DATA my_module = { STANDARD20_MODULE_STUFF, NULL, /* create per-dir config */ NULL, /* merge per-dir config */ NULL, /* server config */ NULL, /* merge server config */ NULL, /* command apr_table_t */ my_register_hooks /* register hooks */ }; Here I'm setting the status code to DECLINED, but I've also tried setting it to HTTP_NOT_MODIFIED, and I've tried setting the remote r->status to that too. Clearly that's the wrong thing to do. What should I be setting? Or should I do this a different way altogether? James.