tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johnny Kewl" <>
Subject Re: Etags vs Week Etags
Date Wed, 03 Sep 2008 17:12:21 GMT

----- Original Message ----- 
From: "Yoryos" <>
To: <>
Sent: Wednesday, September 03, 2008 1:14 PM
Subject: Etags vs Week Etags

> Hi all,
> I don't know if I should be postting the the dev list but let's try from
> here.
> I'm trying to understand how the etag are being applying to the static
> resources. My problem is that I would like to get rid of the week etags,
> that tomcat is applying. After a little bit of searching I ended up to the
> org.apache.naming.resources.ResourceAttributes class where I found the
> getETag(boolean strong) method. It's a very small method but I didn't
> understand a small thing. Well the method is the above:
>    public String getETag(boolean strong) {
>        String result = null;
>        if (attributes != null) {
>            Attribute attribute = attributes.get(ETAG);
>            if (attribute != null) {
>                try {
>                    result = attribute.get().toString();
>                } catch (NamingException e) {
>                    ; // No value for the attribute
>                }
>            }
>        }
>        if (strong) {
>            // The strong ETag must always be calculated by the resources
>            result = strongETag;
>        } else {
>            // The weakETag is contentLenght + lastModified
>            if (weakETag == null) {
>                weakETag = "W/\"" + getContentLength() + "-"
>                    + getLastModified() + "\"";
>            }
>            result = weakETag;
>        }
>        return result;
>    }
> And my question is what the first if condition stand's for. Even if we'll
> get an etag value (result = attribute.get().toString();), exatly after the
> first if block, we get if / else blocks witch results to overriding the
> previous result value to a strongETag or a weekETag!
> What made me trying to find what is going on is that I always get week 
> etags
> for my static resources, witch is something I whould like to overcome as
> some browsers doesn't handle them really well.
> Thank you!

Flipping good question... and I have a feeling that there is some philosophy 
in the answer... reasons for the way it done...
The short answer is that you cant (I think)... the default servlet makes em 
weak (thats the philamamasomamy)...
That first section (strong) does nothing... the reason is that the setEtag 
method is there but as far as i can tell, never ever called by anything in 
Its a hook...

But stay calm... there are ways...

This clever guy did this...

He is basically overriding the default servlet stuff to get things done.... 
its smart, he knows his tomcat, but personally I dont like it...

I think the generic problem is that a static resource cant control its 
Etag... its a dumb image, and secondly no matter what a web server does, 
another web server is going to do it different, so strong loses its meaning 
(more philamamasomamy)... or more simply, you just got to do it yourself...

I would prefer (or try, I havnt giving this a go)... make a little servlet, 
set the Etag headers yourself, map it to all the static resources you want 
to control...
And then do what you have to

getContentLength() + "-" + getLastModified() + IncludeFiles() + 
IncludedImages() + WhateEver() "\"";

etc... I think thats easiest...

The philamamasomamy on why TC chose to make it weak would be interesting to 
hear, but I do think that any serious scheme... on its way to some kind of 
private RSS system... will be doing its own thing.

Have fun... nice question

The most powerful application server on earth.
The only real POJO Application Server.
See it in Action :

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message