httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Dumpleton" <graham.dumple...@gmail.com>
Subject Re: Question: how to change the request in input filter and pass it to proxy
Date Thu, 03 Apr 2008 04:58:47 GMT
This technique is taken from modules/proxy/mod_proxy.c in Apache
source code. See the proxy_detect() function in that file for a C code
example.

One could change request headers on way through in same handler
function as setup the proxy. Still need an output filter if you want
to change handlers in response. I haven't used input/output filters
that modify headers, so can't comment on that.

Graham

On 03/04/2008, Olexandr Prokhorenko <prokhorenko@gmail.com> wrote:
> Hi,
>
>  Do I understand you right and you're proposing to have just an Apache module
>  (not a hook on either output or input filter) and modify the request then?
>
>  I'd be very thankful if you can point me to any typical C code example doing
>  that.  I'm not very good at Python and never used to code with it.  While I
>  think that I understand what you're talking about, I'd be much comfortable
>  with being able to sneak at the example ;)
>
>  What I will also need is to rewrite cookies.   Will I be able to do that
>  this way as well?  I decided to try on input filter just because I thought I
>  may get in troubles rewriting the cookies.  I'll also need to modify the
>  proxy response, so it's a place for output filter, isn't it?
>
>  Thanks, your reply was very quick.
>
>  On Wed, Apr 2, 2008 at 9:39 PM, Graham Dumpleton <graham.dumpleton@gmail.com>
>  wrote:
>
>
>  > On 03/04/2008, Olexandr Prokhorenko <prokhorenko@gmail.com> wrote:
>  > > Hi everyone,
>  > >
>  > >  I am working on the input filter which is going to catch on input
>  > requests,
>  > >  find the bucket with "Host: ", modify it and pass it through.  I will
>  > modify
>  > >  it to something that does not belong to my httpd server, so I need to
>  > pass
>  > >  it through the proxy module (my guess ;).  I can't use either the
>  > static
>  > >  ProxyPass or ProxyReversePass, because the host will be modified
>  > dynamically
>  > >  and it will depend on what is called and substitute it from the
>  > database
>  > >  call.
>  > >
>  > >  It wasn't a big deal to catch on the Host: (well, I may also need to
>  > look
>  > >  for something like GET http://blablabla.com/, but this is not the
>  > highest
>  > >  priority now).  I have created a new HEAP bucket, put it instead of an
>  > >  original one, however, a) it looks to me that Apache makes a call and
>  > gives
>  > >  an error saying file wasn't found, however the Web page displayed is
>  > the
>  > >  correct one, like not being rewritten, and the httpd child crashes; and
>  > b) I
>  > >  need to send it to proxy somehow and pass the call to it.
>  > >
>  > >  I am not very good on concept, my book on Apache modules is still on
>  > the
>  > >  way, but I'd very appreciate any hints on this.
>  > >
>  > >  Thank you.  I'd very thankful for cc: me as well.
>  >
>  > I think you may perhaps be going about this the wrong way. One can
>  > cause a request to be proxied by doing something like the following.
>  > This example uses mod_python, but could be done in C code or mod_perl
>  > as well.
>  >
>  > import posixpath
>  >
>  > from mod_python import apache
>  >
>  > def fixuphandler(req):
>  >
>  >  if req.proxyreq:
>  >    return apache.DECLINED
>  >
>  >  normalised_uri = posixpath.normpath(req.uri)
>  >
>  >  if normalised_uri:
>  >    if normalised_uri != '/' and req.uri[-1] == '/':
>  >      normalised_uri += '/'
>  >
>  >  length = len(req.filename)
>  >  length -= len(req.hlist.directory) - 1
>  >  length += len(req.path_info or '')
>  >
>  >  baseurl = normalised_uri[:-length]
>  >  path = normalised_uri[len(baseurl):]
>  >
>  >  # THIS IS THE IMPORTANT BIT WHICH SETS UP PROXY.
>  >
>  >  req.proxyreq = apache.PROXYREQ_REVERSE
>  >  req.uri = 'http://www.dscpl.com.au' + path
>  >  req.filename = 'proxy:%s' % req.uri
>  >  req.handler = 'proxy-server'
>  >
>  >  return apache.OK
>  >
>  > If you didn't want to proxy a particular request, just return DECLINED
>  > when you know so.
>  >
>  > Graham
>  >
>
>
>
>
> --
>  Alexander Prohorenko.
>

Mime
View raw message