Bug 51258

Summary: new features for mod_substitute
Product: Apache httpd-2 Reporter: horowity@checkpoint.com <horowity>
Component: mod_substituteAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: REOPENED ---    
Severity: enhancement CC: fumiyas-u-apache, horowity, marc.stern
Priority: P2 Keywords: PatchAvailable
Version: 2.2.17   
Target Milestone: ---   
Hardware: All   
OS: All   
Bug Depends on: 51231    
Bug Blocks: 47220    
Attachments: Patch + new .h file as gzipped tarball
Update of original patch.

Description horowity@checkpoint.com 2011-05-24 13:21:45 UTC
features included:
1. Support for SubstituteCond - ability to apply substitute rule only if the configured conditions are met.
   The conditions input could be compared to request data, environment variables and internal Apache notes.
   -- This section is similiar to RewriteCond, and I think it should go to a common section in the code.

2. Support for SubstituteCheck – ability to perform quick search on the data and use the results in order to avoid using “expensive” regular expression.

3. Supporting evaluation (at run time) of the searched and replaced patterns before application (instead of static evaluation in configuration time).
    Evaluation result could be taken from request/response headers, environment variables and internal Apache notes.

4. Adding some more options:

    a. Skip the replaced text from being processed by following rules.
       -- For this, I used a binary tree, which I didn't find in APR, can you consider adding such implementation to APR?

    b. Stop applying other rules after specific rule is matched.

    c.	Option not to break the response into lines (and apply the substitute rules on the whole response).
	
I know these changes need documentation, which I can provide, just I want to know if they will accepted into the trunk, before writing it.

I hope you will find these changes helpful, and I'll be glad to hear your opinion about them.
Comment 1 horowity@checkpoint.com 2011-05-24 13:24:25 UTC
Created attachment 27051 [details]
Patch + new .h file as gzipped tarball
Comment 2 horowity@checkpoint.com 2011-05-24 13:28:11 UTC
*** Bug 47220 has been marked as a duplicate of this bug. ***
Comment 3 William A. Rowe Jr. 2011-05-24 16:42:57 UTC
Thank you for your interest, and contribution.

Note that it is very unlikely to be adopted at this time, as httpd 2.3-beta
(soon to be 2.4) deprecated mod_substitute, and introduced mod_sed.

I'd strongly encourage you to review mod_sed and determine if any of the
improvements you propose to mod_substitute remain applicable to mod_sed,
and absolutely offer them as a patch to httpd 2.3.

All this said, httpd is a collaborative environment, and I will leave your
ticket open for others to evaluate.  It's entirely possible you would find
enough httpd committers to entertain the idea of restoring an enhanced
mod_substitute, if mod_sed is not so easily tailored.
Comment 4 horowity@checkpoint.com 2011-05-24 18:31:56 UTC
Hi

I think that mod_substitute with my new features is doing very good job (depends on Admin configuration).
I don't see any reason why to dreprecate the existing mod_substitute (taking into account that new module usually brings new bugs).

Since mod_sed is not exist in "released" version, it is hard for me to use it in my environement (and I'm quite sure there are many developers with this problem).

Why not give the user option to choose which module she wants to use?

Regards,

Yehezkel
Comment 5 Chris 2014-03-27 19:57:26 UTC
I've tried the patch specifically to substitute in environment variables (%{env:var_name}) but it seems to only allow access to local variables created by the use of 'define' (${var_name}).

Please could you confirm how your code is to be used in this manner?
Comment 6 Chris 2014-03-28 18:10:58 UTC
Thanks Yehezkel,

For anyone else who has this problem - it can be fixed by appending 'e' to the substitution command.
Comment 7 ambqqpdp 2015-06-18 10:36:07 UTC
How to use the patch file? Can't seem to use it with patch tool for Windows.

Thanks!
Comment 8 horowity@checkpoint.com 2015-06-18 11:17:19 UTC
(In reply to ambqqpdp from comment #7)
> How to use the patch file? Can't seem to use it with patch tool for Windows.
> 
> Thanks!

It was created with Unix diff command.
Use Unix patch command to apply it.
Comment 9 Yann Ylavic 2015-06-18 11:32:05 UTC
Hmm, it seems that the attachement is a tar.gz at first.
The patch itself may be contained.
Comment 10 ambqqpdp 2015-06-19 03:26:37 UTC
(In reply to Yann Ylavic from comment #9)
> Hmm, it seems that the attachement is a tar.gz at first.
> The patch itself may be contained.

I tried saving it as tar.gz but uncompressing it returns an error. I will try horowity's suggestion. Thanks!
Comment 11 ambqqpdp 2015-06-19 04:57:40 UTC
(In reply to horowity@checkpoint.com from comment #8)
> (In reply to ambqqpdp from comment #7)
> > How to use the patch file? Can't seem to use it with patch tool for Windows.
> > 
> > Thanks!
> 
> It was created with Unix diff command.
> Use Unix patch command to apply it.

patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.
Comment 12 Rainer Jung 2015-06-19 06:34:20 UTC
Comment on attachment 27051 [details]
Patch + new .h file as gzipped tarball

The attachment is in tar.gz format. I have changed the meta data so that browsers won't try to display the raw binary file.
Comment 13 ambqqpdp 2015-06-19 07:01:34 UTC
(In reply to Rainer Jung from comment #12)
> Comment on attachment 27051 [details]
> Patch + new .h file as gzipped tarball
> 
> The attachment is in tar.gz format. I have changed the meta data so that
> browsers won't try to display the raw binary file.

Thank you very much
Comment 14 ambqqpdp 2015-06-29 04:12:27 UTC
I'm having problems upon compiling the patched source when targeting Apache 2.2, but for 2.4 it's perfectly working. The error seems to be coming from some functions not defined in 2.2 such as ap_regexec_len, etc.
Comment 15 horowity@checkpoint.com 2015-10-14 07:05:09 UTC
(In reply to ambqqpdp from comment #14)
> I'm having problems upon compiling the patched source when targeting Apache
> 2.2, but for 2.4 it's perfectly working. The error seems to be coming from
> some functions not defined in 2.2 such as ap_regexec_len, etc.

The ap_regexec_len was submitted in #51231, and is very easy to adopt.
So if you need these features in 2.2.x - you can just apply both of patches.
Comment 16 horowity@checkpoint.com 2015-10-14 07:15:08 UTC
Created attachment 33182 [details]
Update of original patch.

In how, the original patch is not applying to 2.2.x any more due to a code change, so I attach an update patch.
Comment 17 horowity@checkpoint.com 2015-10-14 07:21:13 UTC
Hi

several years were passed since my original commit and I got several private mails with questions about the patch, so you might want to reconsider adopting the patch to 2.4/trunk (even if mod_sed is considered as replacement of mod_substitute).

Anyhow, the original patch is not applying to 2.2.x any more due to a code change, so I attach an update patch (#33182).

Regards,
Yehezkel Horowitz