You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Paul J. Reder" <re...@remulak.net> on 2003/12/05 23:34:26 UTC
[Patch] Hook to allow insertion of filters during error processing
This patch addresses PRs 24884 and 25123. Please see my note at
http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=106947094322141&w=2
for a full explanation of the problem with code references.
Basically, 304s are supposed to include Expires headers if they may
have changed since the last request. Currently Apache only runs a
small fixed set of filters during error processing and there is currently
no way to add some filters back in to the output filter chain without
adding all of them back in.
This patch allows each individual filter to decide whether it is safe and
pertinent for use during error processing. A hook (the ihs_insert_error_filter
hook, in this case - pending acceptance) is run during error processing
(after the filters have been unloaded) that allows a filter to add itself
back in.
This has several desireable effects:
>> Current default behavior is maintained unless a filter takes explicit
action to add itself back in
>> Filters add themselves back in according to the same filter-type as
before, so the order that filters get called is maintained
>> No change to the api
I don't see any undesireable effects. Does anyone else?
This, or something like it, is needed to address the RFC violation of
not returning an Expires header in 304 responses. It may also be helpful
in solving other issues related to mod_headers or other filters that should
do some processing during errors.
--
Paul J. Reder
-----------------------------------------------------------
"The strength of the Constitution lies entirely in the determination of each
citizen to defend it. Only if every single citizen feels duty bound to do
his share in this defense are the constitutional rights secure."
-- Albert Einstein
Index: httpd-2.0/include/http_protocol.h
===================================================================
RCS file: /home/cvs/httpd-2.0/include/http_protocol.h,v
retrieving revision 1.84
diff -u -r1.84 http_protocol.h
--- httpd-2.0/include/http_protocol.h 3 Feb 2003 17:52:53 -0000 1.84
+++ httpd-2.0/include/http_protocol.h 5 Dec 2003 22:14:33 -0000
@@ -74,6 +74,13 @@
* @package HTTP protocol handling
*/
+/**
+ * This hook allows modules to insert filters for the current error response
+ * @param r the current request
+ * @ingroup hooks
+ */
+AP_DECLARE_HOOK(void,insert_error_filter,(request_rec *r))
+
/* This is an optimization. We keep a record of the filter_rec that
* stores the old_write filter, so that we can avoid strcmp's later.
*/
Index: httpd-2.0/modules/http/http_protocol.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/http/http_protocol.c,v
retrieving revision 1.473
diff -u -r1.473 http_protocol.c
--- httpd-2.0/modules/http/http_protocol.c 16 Nov 2003 02:09:13 -0000 1.473
+++ httpd-2.0/modules/http/http_protocol.c 5 Dec 2003 22:14:35 -0000
@@ -182,6 +182,11 @@
"510 Not Extended"
};
+APR_HOOK_STRUCT(
+ APR_HOOK_LINK(insert_error_filter)
+)
+
+AP_IMPLEMENT_HOOK_VOID(insert_error_filter, (request_rec *r), (r))
/* The index of the first bit field that is used to index into a limit
* bitmask. M_INVALID + 1 to METHOD_NUMBER_LAST.
@@ -2341,6 +2346,8 @@
*/
r->output_filters = r->proto_output_filters;
+
+ ap_run_insert_error_filter(r);
/*
* It's possible that the Location field might be in r->err_headers_out
Index: httpd-2.0/modules/metadata/mod_expires.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/metadata/mod_expires.c,v
retrieving revision 1.48
diff -u -r1.48 mod_expires.c
--- httpd-2.0/modules/metadata/mod_expires.c 22 Nov 2003 02:11:00 -0000 1.48
+++ httpd-2.0/modules/metadata/mod_expires.c 5 Dec 2003 22:14:35 -0000
@@ -205,6 +205,7 @@
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
+#include "http_protocol.h"
typedef struct {
int active;
@@ -585,6 +586,7 @@
{
ap_register_output_filter("MOD_EXPIRES", expires_filter, NULL,
AP_FTYPE_CONTENT_SET);
+ ap_hook_insert_error_filter(expires_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_insert_filter(expires_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
}
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by "Paul J. Reder" <re...@remulak.net>.
Geoffrey Young wrote:
> I can see how that might work in some (even most) circumstances. but
> requiring filters to rewrite things like default_handler just because it
> makes it difficult to behave properly is asking a bit much. but
> default_handler and mod_autoindex are the only core things I can think of at
> the moment :)
Not rewrite any existing handlers, and certainly not rewrite the default_handler,
just create and insert their own handler that runs before the default_handler.
These types of handlers can be very simple and easy to write. Mostly they would
just check some data (maybe headers), set some flags or headers, and install a
filter for later processing.
>>I believe the decision was also motivated by a desire to make the 304
>>as streamlined as possible. Why run a 304 through *all* of the filters and
>>associated processing if the effort was just to be thrown away and a 304
>>sent.
>
>
> precisely because you can't possibly know whether the 304 is valid until
> every potentially-content-altering filter has run - because we're offering a
> filtering API (as opposed to only supporting core filters), each third party
> filter can use _absolutely whatever criteria it wants_ to decide whether it
> will alter the content. I could give an(other) example, but I fear people
> on the list are tiring of this already, so I'll give it a rest :)
Agreed, doing the short circuited version is not 100% accurate under every
circumstance. I think the hope was that between filter_init and handler/filter
hybrids we could cover all the exception cases. It might not be the easiest
method, but it provides the easy and optimized approach for most of the default
cases. There was a lot of effort to avoid programming the default behavior to
the handle exception case since this adds a performance burden on the normal path.
This may be a case where we decided to shortcircuit and shouldn't have.
>>I agree that this is a potential pitfall. Perhaps not all situations can be
>>addressed by a handler/filter hybrid. But moving the meets_condition logic
>>to a filter doesn't address all of what my fix does.
>
>
> ...
>
>
>>My feeling right now is to commit
>>my patch and address the meets_condition question as a seperate issue.
>
>
> yes, I'm terribly sorry that the two got jumbled together, thus distracting
> potential reviewers away from your work - it's entirely my fault.
You brought up a good, and related, issue. That's your fault. :)
> so, I'll end it here :)
I think the meets_condition issue you bring up is valid and needs to be talked
about and addressed. Please don't let it drop. I just think my patch covers
more than the 304 case that caught your attention and is thus a somewhat
seperate issue. (related, but seperate) I didn't mean my declaration to commit
as an end to discussing your issue.
> --Geoff
>
>
--
Paul J. Reder
-----------------------------------------------------------
"The strength of the Constitution lies entirely in the determination of each
citizen to defend it. Only if every single citizen feels duty bound to do
his share in this defense are the constitutional rights secure."
-- Albert Einstein
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>
>> the way Apache chose to work around this was to add the filter_init
>> callback
>> to allow filters to add processing just prior to content generation.
>> presumably, this is where filters could call ap_update_mtime or
>> whatnot to
>> add their information in the conditional GET calculations. the
>> decision to
>> use filter_init over putting ap_meets_conditions logic in its own
>> filter was
>> made in order to let the (presumably) most popular case -
>> default_handler +
>> mod_deflate - be as fast as possible,
>
>
> This isn't entirely true. Yes, there is the filter-init callback, but
> the other
> accepted solution is to create a handler/filter hybrid (such as the
> cache code).
> The handler participates in making sure all the pieces and parts
> required to
> make a good decision are present, then the filter acts on the final
> decision.
> The handler can insert the desired filter.
I can see how that might work in some (even most) circumstances. but
requiring filters to rewrite things like default_handler just because it
makes it difficult to behave properly is asking a bit much. but
default_handler and mod_autoindex are the only core things I can think of at
the moment :)
>
> I believe the decision was also motivated by a desire to make the 304
> as streamlined as possible. Why run a 304 through *all* of the filters and
> associated processing if the effort was just to be thrown away and a 304
> sent.
precisely because you can't possibly know whether the 304 is valid until
every potentially-content-altering filter has run - because we're offering a
filtering API (as opposed to only supporting core filters), each third party
filter can use _absolutely whatever criteria it wants_ to decide whether it
will alter the content. I could give an(other) example, but I fear people
on the list are tiring of this already, so I'll give it a rest :)
> I agree that this is a potential pitfall. Perhaps not all situations can be
> addressed by a handler/filter hybrid. But moving the meets_condition logic
> to a filter doesn't address all of what my fix does.
...
> My feeling right now is to commit
> my patch and address the meets_condition question as a seperate issue.
yes, I'm terribly sorry that the two got jumbled together, thus distracting
potential reviewers away from your work - it's entirely my fault.
so, I'll end it here :)
--Geoff
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by "Paul J. Reder" <re...@remulak.net>.
Geoffrey Young wrote:
>
> Jeff Trawick wrote:
>
>>Geoffrey Young wrote:
>>
>>
>>>I've griped a bit before about having default_handler make conditional
>>>GET
>>>decisions, and this is probably another instance where having
>>>ap_meets_conditions in it's own filter could avoid inevitable problems.
>>>
>>>I'm up for laying out my issues if the list is interested in them and
>>>reevaluating the whole meets_conditions/filter_init stuff.
>>
>>
>>please do
>
>
> ok. it's been outlined before in the archives in bits and pieces, but here
> is essentially the problem...
>
> with the advent of output filters, content handlers (such as
> default_handler) can't possibly have enough information to accurately
> determine whether a 304 is warranted. the issue is, of course, that later
> filters might alter content to the point where the 304 would have been wrong.
...as in the case of mod_include which alters or unsets the Last-Modified value.
> the way Apache chose to work around this was to add the filter_init callback
> to allow filters to add processing just prior to content generation.
> presumably, this is where filters could call ap_update_mtime or whatnot to
> add their information in the conditional GET calculations. the decision to
> use filter_init over putting ap_meets_conditions logic in its own filter was
> made in order to let the (presumably) most popular case - default_handler +
> mod_deflate - be as fast as possible,
This isn't entirely true. Yes, there is the filter-init callback, but the other
accepted solution is to create a handler/filter hybrid (such as the cache code).
The handler participates in making sure all the pieces and parts required to
make a good decision are present, then the filter acts on the final decision.
The handler can insert the desired filter.
I believe the decision was also motivated by a desire to make the 304
as streamlined as possible. Why run a 304 through *all* of the filters and
associated processing if the effort was just to be thrown away and a 304 sent.
This is why the error processing removed the filters. It was just too
agressive about it without providing a way to undo the removal where necessary.
Also, your comments and observations hold some merit in relation to a 304
(understandably, since that is the primary motivator for my patch), but this
fix also applies equally to other errors (including all the 300's and 200's).
The alternate option of moving the ap_meets_conditions logic does not address
these other non-304 errors.
> now, I wasn't present for that discussion (some of which happened on #irc)
> but that's how it looks like it happened to me from the archives. I
> certainly don't mean to misrepresent things if I'm not entirely accurate -
> please speak up if I've missed something.
>
> so, for the most part how things are currently works for core. however, the
> first time I tried to use output filters with conditional GET logic I saw
> that the idea fell short.
>
> just using current 2.1 core you can see for yourself how filter_init is
> suboptimal. here's an Apache-Test tarball you can view or run if you like
> (keep in mind it's 2.1 specific)
>
> http://perl.apache.org/~geoff/bug-ap_meets_conditions.tar.gz
>
> basically, what this tarball shows is that the filter_init won't run when
> the content-type is set during content-generation and the filter is added
> via AddOutputFilterByType. while this particular example might seem a bit
> abnormal, it was one I could quickly see that didn't involve anything other
> than core modules.
>
> the basic problem, however, isn't in AddOutputFilterByType, it's in the
> entire idea that conditional GET logic can be fully accommodated via
> filter_init processing. basically, filters that rely on decisions made by
> content-generators are left in a catch-22: if they add logic to the request
> via filter_init they risk that logic being wrong due to later decisions, or
> if they postpone the logic until after content-generation they risk never
> having it called at all.
I agree that this is a potential pitfall. Perhaps not all situations can be
addressed by a handler/filter hybrid. But moving the meets_condition logic
to a filter doesn't address all of what my fix does. It also introduces the
possibility of doing a lot of extra work that gets discarded. We are stuck in
a bit of a dilemma, as I see it. We can run ap_meets_conditions early to avoid
unnecessary cycles and risk sending 304's when we might not have, or wait until
the last possible moment to check meets_conditions and be as accurate as possible
at the price of performance. The 304 is supposed to be a time and bandwidth
saver, this might reduce it to a bandwidth saver only.
> hopefully, this kind of makes sense to at least some people. personally,
> the only thing that makes sense to me is moving conditonal GET logic to it's
> own filter, similar to Content-Length I suppose. yes, it would slow down
> the server for default+deflate responses, but I guess that would be the
> trade-off for allowing people to properly control the cache-correctness of
> their responses (among other things).
>
>
>>I have the *feeling* that Paul's patch is a very safe fix (i.e., no
>>regression for 2.0.x) for the missing Expires on 304, and in general I
>>like the idea of a module getting the chance to add a filter on the
>>error path, but I have no awareness of other problems caused by the
>>present meets-conditions handling.
>>
>
>
> I haven't looked at this particular issue to know whether the two ideas are
> mutually exclusive, but I can't help but wonder if the problem would go away
> if meets_conditons were held back until the very last moment. we might be
> talking about two different things, though :)
I think there is some concept overlap but there are issues solved by my patch
that aren't addressed by your suggestion. My feeling right now is to commit
my patch and address the meets_condition question as a seperate issue. Moving
the meets_condition code also impacts other modules (such as mod_cache)
which would need to be updated to work properly. Moving the meets_condition
code may make the 304 related aspects of my patch irrelevant, but I suspect
it will still need to be there for other errors.
> anyway, as usual, thanks for listening.
>
> --Geoff
>
>
--
Paul J. Reder
-----------------------------------------------------------
"The strength of the Constitution lies entirely in the determination of each
citizen to defend it. Only if every single citizen feels duty bound to do
his share in this defense are the constitutional rights secure."
-- Albert Einstein
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
> Stas Bekman wrote:
>
>>Geoffrey Young wrote:
>>[...]
>>
>>
>>>hopefully, this kind of makes sense to at least some people. personally,
>>>the only thing that makes sense to me is moving conditonal GET logic
>>>to it's
>>>own filter, similar to Content-Length I suppose. yes, it would slow down
>>>the server for default+deflate responses, but I guess that would be the
>>>trade-off for allowing people to properly control the
>>>cache-correctness of
>>>their responses (among other things).
>>
>>
>>What if you use a plain connection filter to manipulate the headers and
>>remove it the moment the output headers have been sent? If understand
>>correctly you want this filter to be triggered the moment the first bit
>>of the response body is sent (if any). Could this be then done by a
>>response body filter which will then immediately remove itself from the
>>filters stack?
>
>
> maybe - I don't really understand why you would need to remove it.
You said:
> personally, the only thing that makes sense to me is moving conditonal
> GET logic to it's own filter, similar to Content-Length I suppose.
> yes, it would slow down the server for default+deflate responses...
So I suggested to remove it as soon as its job is done to reduce the slowdown
the very minimal.
Notice that if this is going to be the first connection filter you won't be
able to remove it, because of the bug in the filters implementation in httpd.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Stas Bekman wrote:
> Geoffrey Young wrote:
> [...]
>
>> hopefully, this kind of makes sense to at least some people. personally,
>> the only thing that makes sense to me is moving conditonal GET logic
>> to it's
>> own filter, similar to Content-Length I suppose. yes, it would slow down
>> the server for default+deflate responses, but I guess that would be the
>> trade-off for allowing people to properly control the
>> cache-correctness of
>> their responses (among other things).
>
>
> What if you use a plain connection filter to manipulate the headers and
> remove it the moment the output headers have been sent? If understand
> correctly you want this filter to be triggered the moment the first bit
> of the response body is sent (if any). Could this be then done by a
> response body filter which will then immediately remove itself from the
> filters stack?
maybe - I don't really understand why you would need to remove it. but
whether it's an intermediate filter that can be removed or whatever is
secondary - until people buy into whether conditional GET logic ought to be
in a filter at all (and thus after _all_
content-generating-and-manipulating filter have run) there's really no point
in figuring out an implementation. that is, probably - if people just want
to see code, then I guess we can work up something, too :)
--Geoff
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
[...]
> hopefully, this kind of makes sense to at least some people. personally,
> the only thing that makes sense to me is moving conditonal GET logic to it's
> own filter, similar to Content-Length I suppose. yes, it would slow down
> the server for default+deflate responses, but I guess that would be the
> trade-off for allowing people to properly control the cache-correctness of
> their responses (among other things).
What if you use a plain connection filter to manipulate the headers and remove
it the moment the output headers have been sent? If understand correctly you
want this filter to be triggered the moment the first bit of the response body
is sent (if any). Could this be then done by a response body filter which will
then immediately remove itself from the filters stack?
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Jeff Trawick wrote:
> Geoffrey Young wrote:
>
>> I've griped a bit before about having default_handler make conditional
>> GET
>> decisions, and this is probably another instance where having
>> ap_meets_conditions in it's own filter could avoid inevitable problems.
>>
>> I'm up for laying out my issues if the list is interested in them and
>> reevaluating the whole meets_conditions/filter_init stuff.
>
>
> please do
ok. it's been outlined before in the archives in bits and pieces, but here
is essentially the problem...
with the advent of output filters, content handlers (such as
default_handler) can't possibly have enough information to accurately
determine whether a 304 is warranted. the issue is, of course, that later
filters might alter content to the point where the 304 would have been wrong.
the way Apache chose to work around this was to add the filter_init callback
to allow filters to add processing just prior to content generation.
presumably, this is where filters could call ap_update_mtime or whatnot to
add their information in the conditional GET calculations. the decision to
use filter_init over putting ap_meets_conditions logic in its own filter was
made in order to let the (presumably) most popular case - default_handler +
mod_deflate - be as fast as possible,
now, I wasn't present for that discussion (some of which happened on #irc)
but that's how it looks like it happened to me from the archives. I
certainly don't mean to misrepresent things if I'm not entirely accurate -
please speak up if I've missed something.
so, for the most part how things are currently works for core. however, the
first time I tried to use output filters with conditional GET logic I saw
that the idea fell short.
just using current 2.1 core you can see for yourself how filter_init is
suboptimal. here's an Apache-Test tarball you can view or run if you like
(keep in mind it's 2.1 specific)
http://perl.apache.org/~geoff/bug-ap_meets_conditions.tar.gz
basically, what this tarball shows is that the filter_init won't run when
the content-type is set during content-generation and the filter is added
via AddOutputFilterByType. while this particular example might seem a bit
abnormal, it was one I could quickly see that didn't involve anything other
than core modules.
the basic problem, however, isn't in AddOutputFilterByType, it's in the
entire idea that conditional GET logic can be fully accommodated via
filter_init processing. basically, filters that rely on decisions made by
content-generators are left in a catch-22: if they add logic to the request
via filter_init they risk that logic being wrong due to later decisions, or
if they postpone the logic until after content-generation they risk never
having it called at all.
hopefully, this kind of makes sense to at least some people. personally,
the only thing that makes sense to me is moving conditonal GET logic to it's
own filter, similar to Content-Length I suppose. yes, it would slow down
the server for default+deflate responses, but I guess that would be the
trade-off for allowing people to properly control the cache-correctness of
their responses (among other things).
>
> I have the *feeling* that Paul's patch is a very safe fix (i.e., no
> regression for 2.0.x) for the missing Expires on 304, and in general I
> like the idea of a module getting the chance to add a filter on the
> error path, but I have no awareness of other problems caused by the
> present meets-conditions handling.
>
I haven't looked at this particular issue to know whether the two ideas are
mutually exclusive, but I can't help but wonder if the problem would go away
if meets_conditons were held back until the very last moment. we might be
talking about two different things, though :)
anyway, as usual, thanks for listening.
--Geoff
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Jeff Trawick <tr...@attglobal.net>.
Geoffrey Young wrote:
> I've griped a bit before about having default_handler make conditional GET
> decisions, and this is probably another instance where having
> ap_meets_conditions in it's own filter could avoid inevitable problems.
>
> I'm up for laying out my issues if the list is interested in them and
> reevaluating the whole meets_conditions/filter_init stuff.
please do
I have the *feeling* that Paul's patch is a very safe fix (i.e., no regression
for 2.0.x) for the missing Expires on 304, and in general I like the idea of a
module getting the chance to add a filter on the error path, but I have no
awareness of other problems caused by the present meets-conditions handling.
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
Geoffrey Young wrote:
>
> I've griped a bit before about having default_handler make conditional GET
> decisions, and this is probably another instance where having
> ap_meets_conditions in it's own filter could avoid inevitable problems.
i see how paul's patch would reawaken thinking on the subject, but
your issue doesn't appear to relate directly to the patch. there
are other bugs which can be fixed using the error-path filter -- such
as the non-transference of custom header fields on external redirects.
that has nothing to do with conditional GETs, so i'm definitely +1
on this patch because it currently allows fixing at least two issues,
even if one of them (the expires/304 bit) may end up getting fixed
another way at some point in the future.
--
#ken P-)}
Ken Coar, Sanagendamgagwedweinini http://Golux.Com/coar/
Author, developer, opinionist http://Apache-Server.Com/
"Millennium hand and shrimp!"
Re: [Patch] Hook to allow insertion of filters during error processing
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Paul J. Reder wrote:
> This patch addresses PRs 24884 and 25123. Please see my note at
> http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=106947094322141&w=2
> for a full explanation of the problem with code references.
I've griped a bit before about having default_handler make conditional GET
decisions, and this is probably another instance where having
ap_meets_conditions in it's own filter could avoid inevitable problems.
I think we were supposed to discuss this at the hackathon, but it never
happened.
I'm up for laying out my issues if the list is interested in them and
reevaluating the whole meets_conditions/filter_init stuff.
--Geoff