You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Nick Kew <ni...@webthing.com> on 2006/09/28 18:16:24 UTC

Regexp-based rewriting for mod_headers?

We have a problem with DAV + SSL hardware.
It appears to be the issue described in
http://svn.haxx.se/users/archive-2006-03/0549.shtml

It seems to me that the ability to rewrite a request header
will fix that.  As a generic fix, I've patched mod_headers
to support regexp-based rewriting of arbitrary headers.

Please review.  If people like this (or if noone objects and I
find the time), I'll document it and commit to /trunk/.

-- 
Nick Kew

Re: Regexp-based rewriting for mod_headers?

Posted by Mads Toftum <ma...@toftum.dk>.
On Thu, Sep 28, 2006 at 05:16:24PM +0100, Nick Kew wrote:
> It seems to me that the ability to rewrite a request header
> will fix that.  As a generic fix, I've patched mod_headers
> to support regexp-based rewriting of arbitrary headers.
> 
+1 from the peanut gallery - I've had to do similar hackery for a
customer and would much prefer to see it supported ;)

vh

Mads Toftum
-- 
`Darn it, who spiked my coffee with water?!' - lwall


Re: Regexp-based rewriting for mod_headers?

Posted by Brian Akins <br...@turner.com>.
+1 on the patch

-- 
Brian Akins
Chief Operations Engineer
Turner Digital Media Technologies

Re: Regexp-based rewriting for mod_headers?

Posted by Nick Kew <ni...@webthing.com>.
On Friday 29 September 2006 15:45, Garrett Rooney wrote:

> My only comment about the patch itself is I'm not overly thrilled
> about recursively processing matches, simply because every time we
> recurse we allocate an entire new string to hold the entire results,
> which seems wasteful.  But on the other hand, any other solution would
> probably be much more complex, and we're not talking about that many
> levels of recursion in any sane configureation, so hey, whatever.
>
> -garrett

I wasn't sure about that myself: a once-only match might be better.

It's actually something of a cop-out for dealing with headers-fixup being
called multiple times over things like mod_dir/mod_negotiation internal
redirects, leading to it being applied an indeterminate number of times.
The alternative is to save state there.

-- 
Nick Kew

Re: Regexp-based rewriting for mod_headers?

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 9/29/06, Nick Kew <ni...@webthing.com> wrote:
> On Thursday 28 September 2006 18:29, Garrett Rooney wrote:
> > On 9/28/06, Nick Kew <ni...@webthing.com> wrote:
> > > We have a problem with DAV + SSL hardware.
> > > It appears to be the issue described in
> > > http://svn.haxx.se/users/archive-2006-03/0549.shtml
> > >
> > > It seems to me that the ability to rewrite a request header
> > > will fix that.  As a generic fix, I've patched mod_headers
> > > to support regexp-based rewriting of arbitrary headers.
> > >
> > > Please review.  If people like this (or if noone objects and I
> > > find the time), I'll document it and commit to /trunk/.
> >
> > The patch seems reasonable, but I've never messed with mod_headers, so
> > bear with me.  It should let you do something like:
> >
> > Header edit <header> <regex> <replace-string>
>
> Exactly (and support mod_headers's optional cond var).
>
> > Right?  Could you provide an example so I can confirm that it's
> > working correctly?
>
> The example that fixes the DAV problem above can be stated as
>
>   RequestHeader edit Destination ^https: http:
>
> Otherwise, one can dream up mod_rewrite like cases; e.g.
> (modulo line wrap)
>
>   Header edit Location ^http://([a-z0-9-]+)\.example\.com/
>                                                 http://example.com/$1/
>
> (not sure if that makes sense, but you get my meaning:-)

Cool.  I just tested it here, and it seems to work fine.  +1 to commit
from me, assuming suitable docs and so forth.

My only comment about the patch itself is I'm not overly thrilled
about recursively processing matches, simply because every time we
recurse we allocate an entire new string to hold the entire results,
which seems wasteful.  But on the other hand, any other solution would
probably be much more complex, and we're not talking about that many
levels of recursion in any sane configureation, so hey, whatever.

-garrett

Re: Regexp-based rewriting for mod_headers?

Posted by Nick Kew <ni...@webthing.com>.
On Thursday 28 September 2006 18:29, Garrett Rooney wrote:
> On 9/28/06, Nick Kew <ni...@webthing.com> wrote:
> > We have a problem with DAV + SSL hardware.
> > It appears to be the issue described in
> > http://svn.haxx.se/users/archive-2006-03/0549.shtml
> >
> > It seems to me that the ability to rewrite a request header
> > will fix that.  As a generic fix, I've patched mod_headers
> > to support regexp-based rewriting of arbitrary headers.
> >
> > Please review.  If people like this (or if noone objects and I
> > find the time), I'll document it and commit to /trunk/.
>
> The patch seems reasonable, but I've never messed with mod_headers, so
> bear with me.  It should let you do something like:
>
> Header edit <header> <regex> <replace-string>

Exactly (and support mod_headers's optional cond var).

> Right?  Could you provide an example so I can confirm that it's
> working correctly?

The example that fixes the DAV problem above can be stated as

  RequestHeader edit Destination ^https: http:

Otherwise, one can dream up mod_rewrite like cases; e.g.
(modulo line wrap)

  Header edit Location ^http://([a-z0-9-]+)\.example\.com/
						http://example.com/$1/

(not sure if that makes sense, but you get my meaning:-)

-- 
Nick Kew

Re: Regexp-based rewriting for mod_headers?

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 9/28/06, Nick Kew <ni...@webthing.com> wrote:
>
> We have a problem with DAV + SSL hardware.
> It appears to be the issue described in
> http://svn.haxx.se/users/archive-2006-03/0549.shtml
>
> It seems to me that the ability to rewrite a request header
> will fix that.  As a generic fix, I've patched mod_headers
> to support regexp-based rewriting of arbitrary headers.
>
> Please review.  If people like this (or if noone objects and I
> find the time), I'll document it and commit to /trunk/.

The patch seems reasonable, but I've never messed with mod_headers, so
bear with me.  It should let you do something like:

Header edit <header> <regex> <replace-string>

Right?  Could you provide an example so I can confirm that it's
working correctly?

-garrett