Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 777F1C9A for ; Wed, 4 May 2011 10:16:01 +0000 (UTC) Received: (qmail 19392 invoked by uid 500); 4 May 2011 10:16:01 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 19359 invoked by uid 500); 4 May 2011 10:16:01 -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 19351 invoked by uid 99); 4 May 2011 10:16:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 May 2011 10:16:01 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [217.22.192.104] (HELO www.elogos.de) (217.22.192.104) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 May 2011 10:15:56 +0000 Received: by www.elogos.de (Postfix, from userid 1001) id BE1E99004B; Wed, 4 May 2011 12:39:19 +0200 (CEST) Date: Wed, 4 May 2011 12:39:19 +0200 From: rm@tuxteam.de To: modules-dev@httpd.apache.org Subject: Re: using mod_proxy for subrequests Message-ID: <20110504103919.GC20933@seid-online.de> References: <20110504093446.GB20933@seid-online.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.15+20070412 (2007-04-11) On Wed, May 04, 2011 at 11:36:35AM +0200, Sorin Manolache wrote: > On Wed, May 4, 2011 at 11:34, wrote: > > Hello list, > > > > as the subject line says, I'm trying to run a subrequest through > > mod_proxy and need to post-process the subrequests response data. > > Looking at older posts on this list it seems as if the only way to > > accomplish this is: > > > > (1) �create a subrequest with ap_sub_req_lookup_uri(...) > > > > (2) modify parts of the created subrequest (filename, handler, proxyreq > > etc.) > > > > (3) Install a filter that captures the response data > > > > (4) run that subrequest > > Play it in conjunction to RewriteRules: > > RewriteCond %{IS_SUBREQ} true > RewriteRule ^/some_name$ > http://backend.host.net/path?query_string [P] Hmm, I don't seem to get what's you do different compared with my approach: > request_rec *subr = ap_sub_req_method_uri("GET", "/some_name", r, NULL); Same as my (1) Here, "/some_name" is still an arbitrary URI and _not_ the proxy URI I want to query. BTW, this does clutter the URL namespace, a big no-no in my usecase ... > ap_add_output_filter(post_processing_filter_name, filter_context, > subr, subr->connection); Same as my (3) > int status = ap_run_subreq(subr); > int http_status = subr->status; > // optional: subr->main = r; > if (ap_is_HTTP_ERROR(status) || ap_is_HTTP_ERROR(http_status)) > // some error handling > } And you still need to _run_ the subrequest to get at the restponse status etc. > > There are some subtleties here: > > 1. The rewrite rules are ran in the translate_name hook. If you want > to use %{ENV:request_note_name} in your rewrite rule, you have to copy > them somehow (for example in another translate_name callback that is > run before the mod_rewrite callbacks) from the main request notes to > the subrequest notes. > > 2. Subrequests are not kept alive. In order to keep them alive, you > could try to hook APR_OPTIONAL_HOOK(proxy, fixups, &proxy_fixups, > NULL, NULL, APR_HOOK_MIDDLE). In the proxy_fixups callback, you can > set subr->main = NULL; Then, after ap_run_subreq, you can re-set > subr->main = r (the "optional" line in the code example above). i But that means loosing all request context in the subrequest! One of tthe main reasons to use mod_proxy instead of some-arbitrary-webclient-lib is the fact that mod_proxy passes all incomming header to the backend server. A must in my case. > I'm > using this trick but I do not know all its consequences. Hmmm - bold. The costs of server downtime might easily exeed my monthly income in this case :-) cheers, RalfD > Sorin > > > > > > Now, (1) seems unelegant since it does need a valid URI which has > > nothing to do with the final proxy request. Hence the value of the > > subrequest's status has no meaning -- but isn't this exactly the purpose > > of subrequests? To quote Nick Kew '....to run a fast partial request, to > > gather information: what would happen if we ran thos request?' > > Is there really no way to create a subrequest directly aiming at > > mod_proxy. > > It would be utterly nice to be able to access a (proxied) subrequests > > metadata (content-type, etag etc.) before running the filter. > > > > Any ideas? Mabe a nice API extension for Apache or mod_proxy? > > > > TIA Ralf Mattes > > > >