tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yoryos <valo...@gmail.com>
Subject Re: Etags vs Week Etags
Date Thu, 04 Sep 2008 10:46:09 GMT
On Thu, Sep 4, 2008 at 1:07 PM, Johnny Kewl <john@kewlstuff.co.za> wrote:

>
> ----- Original Message ----- From: "Yoryos" <valotas@gmail.com>
> To: "Tomcat Users List" <users@tomcat.apache.org>
> Sent: Thursday, September 04, 2008 9:08 AM
>
> Subject: Re: Etags vs Week Etags
>
>
>  On Wed, Sep 3, 2008 at 11:09 PM, Johnny Kewl <john@kewlstuff.co.za>
>> wrote:
>>
>>
>>> ----- Original Message ----- From: "Johnny Kewl" <john@kewlstuff.co.za>
>>> To: "Tomcat Users List" <users@tomcat.apache.org>
>>> Sent: Wednesday, September 03, 2008 9:51 PM
>>>
>>> Subject: Re: Etags vs Week Etags
>>>
>>>
>>>
>>>  ----- Original Message ----- From: "Yoryos" <valotas@gmail.com>
>>>> To: "Tomcat Users List" <users@tomcat.apache.org>
>>>> Sent: Wednesday, September 03, 2008 8:57 PM
>>>> Subject: Re: Etags vs Week Etags
>>>>
>>>>
>>>>  On Wed, Sep 3, 2008 at 8:12 PM, Johnny Kewl <john@kewlstuff.co.za>
>>>>
>>>>> wrote:
>>>>>
>>>>>
>>>>>  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
>>>>>> Tomcat.
>>>>>> Its a hook...
>>>>>>
>>>>>> But stay calm... there are ways...
>>>>>>
>>>>>> This clever guy did this...
>>>>>>
>>>>>>
>>>>>>
>>>>>> http://blog.bcarlso.net/articles/2007/10/19/tomcat-weak-etags-and-javascript-css-caching
>>>>>>
>>>>>> 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
>>>>>>
>>>>>>
>>>>>>
>> Well can anyone also explain to me the first if block of code here:
>>
>>   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;
>>   }
>>
>>
>> I think it is not realy needed!
>>
>
> Yory, I'm tired pulling long hours on something, so please check me ;)
>
> Yes, not needed, its another hook... coder has left it there in case he
> needs it...
> In theory, when I look at the code, all you really have to do is
> setEtag.... and that will be used.
> If you leave the W/\"" off... its a strong tag....
>
> or if you
> if (strong)
>               weakETag = getContentLength() + "-" + getLastModified() +
> "\"";
>
> I think you done... TC will now do strong tags
>
> To understand whats going on with that stuff... attributes is a bunch of
> collections.
> They way its being used is when you drop a static resource into tomcat
> theres a war engine somewhere that detects it...
> When that happens... they stick things in there like ContentLength and
> LastModified... ie the file attributes...
> And then they use the collections to compute the eTag...
> That getContentLength() function is also using those "memory" of
> attributes...
>
> Its a hash map so you can add whatever you need to it.... thus he has left
> the hook in there...
>
> Then things like
> checkIfNoneMatch and all the rest should be in the default servlet... and
> they will all call into the above, so if your
> etag is there... thats going to be used...
>
> In that link ( the clever guy link) all he is doing is getting at the
> setETag function... which comes back as
> strongETag
> and he is getting the stuff out of the collections so that
> he doenst have to recheck the static resource last mod time etc... but
> equally he could have added something... and then the hook gets useful...
>
> It does look unfinished, but this ETag stuff is difficult... say for
> example you have a JSP file and that includes other JSP files... how would
> you code that so that humble users can do it.... probably end up just
> leaving a hook in there as well, for high IQ systems ;)
>
> Remy Maucherat is the default servlet guy... hopefully he can confirm
>
> Have fun...
>

Thanks for the answer!
As I've seen tomcat does not ad the etag header to jsps and other servlets.
That should be the work of the programmer of the servlet. The only thing it
does is addind this header to the static content.

The solution of the clever guy does not seem to work! At least not in tomcat
6 (that I am using, but didn't test it on 5). As I've seen tomcat let's you
define an implementation of the context it can use. The only problem is that
FileDirContext witch overides this clever guy does not implement all the
interfaces it should in order to "work" as a context. Form the other side
StandardContext witch should be extended in order to get something working
does some casting to FileDirContext depending the request.

Anyway I'll try to find a "portable" solution as I wouldn't like to hack the
source of the tomcat in order to have strong etags.

Thank you for your help and time!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message