Re: mod_cache deliver 304 instead of (not so) stale cache entries

2005-05-22 Thread Sander Striker

[EMAIL PROTECTED] wrote:

Sander Striker wrote:

[EMAIL PROTECTED] wrote:


[...]

Might as well not do revalidation in that case; actually that would be
better, because the 304's that are returned may not even be correct.  The
conditions are replaced with the ones from the cache, remember?



Yes, I remember, but I must admit that I am slightly confused now. When should
we avoid revalidation with the conditionals from the cache?


Well, we shouldn't; it's a workaround for a different bug.  The workaround 
however
would be to _never_ use the conditionals from the cache.


If the original request does not contain any conditionals? This is what my 
patch does


What I am trying to point out is that you can't use the conditionals from the
cache at all if the CACHE_SAVE filter isn't being invoked.  You will get a 304 
based
on the conditionals from the cache, which may not be correct with respect to
the conditionals from the request.


[..cut..]

I can see the application.  Are you up for submitting a patch to the
default handler? :)



I have attached a patch for this. Two comments:

1. I am not very familar with buckets and brigades, so please check closely if
   I did it correct (my tests make me think so). If I did something wrong 
feedback
   is appreciated such that I can do it better next time :-)
2. ap_meets_conditions returns 3 different values: OK, HTTP_PRECONDITION_FAILED 
and
   HTTP_NOT_MODIFIED. In my patch I assume that in all cases the response should
   go down the filter chain.


I'll review your patch.  I'll massage it into shape if needed, given your
comments.

Thanks,

Sander


Re: mod_cache deliver 304 instead of (not so) stale cache entries

2005-05-22 Thread r . pluem


Sander Striker wrote:
>> [EMAIL PROTECTED] wrote:
> 
> [...]

[...]

> 
>> I am aware that this forces a full request to the backend for requests
>> without conditionals
>> to expired resources. So I am not very happy with this solution. Maybe
>> it is better to let
>> the default handler pass 304 responses down the filter chain.
> 
> 
> Might as well not do revalidation in that case; actually that would be
> better, because the
> 304's that are returned may not even be correct.  The conditions are
> replaced with the
> ones from the cache, remember?
> 

Yes, I remember, but I must admit that I am slightly confused now. When should
we avoid revalidation with the conditionals from the cache?

If the original request does not contain any conditionals? This is what my 
patch does

[..cut..]

> 
> I can see the application.  Are you up for submitting a patch to the
> default handler? :)

I have attached a patch for this. Two comments:

1. I am not very familar with buckets and brigades, so please check closely if
   I did it correct (my tests make me think so). If I did something wrong 
feedback
   is appreciated such that I can do it better next time :-)
2. ap_meets_conditions returns 3 different values: OK, HTTP_PRECONDITION_FAILED 
and
   HTTP_NOT_MODIFIED. In my patch I assume that in all cases the response should
   go down the filter chain.

Regards

RĂ¼diger

--- core.c.orig 2005-05-21 10:30:23.0 +0200
+++ core.c  2005-05-22 12:08:20.0 +0200
@@ -3492,46 +3492,48 @@ static int default_handler(request_rec *
 ap_set_etag(r);
 apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
 ap_set_content_length(r, r->finfo.size);
-if ((errstatus = ap_meets_conditions(r)) != OK) {
-apr_file_close(fd);
-return errstatus;
-}
-
-if (bld_content_md5) {
-apr_table_setn(r->headers_out, "Content-MD5",
-   ap_md5digest(r->pool, fd));
-}
 
 bb = apr_brigade_create(r->pool, c->bucket_alloc);
 
-/* For platforms where the size of the file may be larger than
- * that which can be stored in a single bucket (where the
- * length field is an apr_size_t), split it into several
- * buckets: */
-if (sizeof(apr_off_t) > sizeof(apr_size_t) 
-&& r->finfo.size > AP_MAX_SENDFILE) {
-apr_off_t fsize = r->finfo.size;
-e = apr_bucket_file_create(fd, 0, AP_MAX_SENDFILE, r->pool,
-   c->bucket_alloc);
-while (fsize > AP_MAX_SENDFILE) {
-apr_bucket *ce;
-apr_bucket_copy(e, &ce);
-APR_BRIGADE_INSERT_TAIL(bb, ce);
-e->start += AP_MAX_SENDFILE;
-fsize -= AP_MAX_SENDFILE;
+if ((errstatus = ap_meets_conditions(r)) != OK) {
+apr_file_close(fd);
+r->status = errstatus;
+} 
+else {
+if (bld_content_md5) {
+apr_table_setn(r->headers_out, "Content-MD5",
+   ap_md5digest(r->pool, fd));
+}
+
+/* For platforms where the size of the file may be larger than
+ * that which can be stored in a single bucket (where the
+ * length field is an apr_size_t), split it into several
+ * buckets: */
+if (sizeof(apr_off_t) > sizeof(apr_size_t) 
+&& r->finfo.size > AP_MAX_SENDFILE) {
+apr_off_t fsize = r->finfo.size;
+e = apr_bucket_file_create(fd, 0, AP_MAX_SENDFILE, r->pool,
+   c->bucket_alloc);
+while (fsize > AP_MAX_SENDFILE) {
+apr_bucket *ce;
+apr_bucket_copy(e, &ce);
+APR_BRIGADE_INSERT_TAIL(bb, ce);
+e->start += AP_MAX_SENDFILE;
+fsize -= AP_MAX_SENDFILE;
+}
+e->length = (apr_size_t)fsize; /* Resize just the last bucket 
*/
 }
-e->length = (apr_size_t)fsize; /* Resize just the last bucket */
-}
-else
-e = apr_bucket_file_create(fd, 0, (apr_size_t)r->finfo.size,
-   r->pool, c->bucket_alloc);
+else
+e = apr_bucket_file_create(fd, 0, (apr_size_t)r->finfo.size,
+   r->pool, c->bucket_alloc);
 
 #if APR_HAS_MMAP
-if (d->enable_mmap == ENABLE_MMAP_OFF) {
-(void)apr_bucket_file_enable_mmap(e, 0);
-}
+if (d->enable_mmap == ENABLE_MMAP_OFF) {
+(void)apr_bucket_file_enable_mmap(e, 0);
+}
 #endif
-APR_BRIGADE_INSERT_TAIL(bb, e);
+APR_BRIGADE_INSERT_TAIL(bb, e);
+}
 e = apr_bucket_eos_create(c->bucket_alloc);
 APR_BRIGADE_INSERT_TAIL(bb, e);
 


Re: mod_cache deliver 304 instead of (not so) stale cache entries

2005-05-21 Thread Sander Striker

[EMAIL PROTECTED] wrote:

[...]

I found out that during the second request which returns a 304 the CACHE_SAVE 
filter,
which would be able to deal with such things (-> (not so) stale cache entries) 
is never
used.
The change of the conditionals in cache_storage.c starting at line 269 leads to 
the creation
of a 304 code in the default handler and the default handler does not pass 304 
responses down
the filter chain.


Then that is a bug.  We've seen the same problem in mod_proxy.


So the 304 response is delivered instead of the (not so) stale cache entry. So 
I created the following
patch to cache_storage.c which prevents the modification or better creation of 
any conditionals
if the original request did not contain any:


No, this is what we were trying to prevent.


I am aware that this forces a full request to the backend for requests without 
conditionals
to expired resources. So I am not very happy with this solution. Maybe it is 
better to let
the default handler pass 304 responses down the filter chain.


Might as well not do revalidation in that case; actually that would be better, 
because the
304's that are returned may not even be correct.  The conditions are replaced 
with the
ones from the cache, remember?


Some might also say that my configuration seems stupid (do disk caching for 
static resources,
which was actually born during some tests for another problem I am currently 
hunting), but
this problem also applies to other providers than mod_disk_cache and the 
document root might
be on a non local disk.


I can see the application.  Are you up for submitting a patch to the default 
handler? :)

Sander