You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Brian Mearns <bm...@ieee.org> on 2010/04/13 16:34:58 UTC

[users@httpd] Custom ETags

I'd like to use stronger and correlated ETag, namely the hash of the
content being served. Obviously it's a drag to do this in-line, so I'm
planning an automated task to generate the ETag values and store them
on the server. Is there any way I can get httpd to grab these stored
values for use in the Etag header? I'm flexible on how I store them:
in a database, in one large file, each in its own file named according
to the resource, etc.

Any ideas?

Thanks,
-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://keys.gnupg.net

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Custom ETags

Posted by Brian Mearns <me...@gmail.com>.
On Tue, Apr 13, 2010 at 2:13 PM, Jonathan Zuckerman
<j....@gmail.com> wrote:
> On Tue, Apr 13, 2010 at 1:20 PM, Brian Mearns <me...@gmail.com> wrote:
>>
>> On Tue, Apr 13, 2010 at 1:13 PM, Jonathan Zuckerman
>> <j....@gmail.com> wrote:
>> >
>> >
>> > On Tue, Apr 13, 2010 at 12:13 PM, Brian Mearns <me...@gmail.com>
>> > wrote:
>> >>
>> >> On Tue, Apr 13, 2010 at 10:49 AM, Jonathan Zuckerman
>> >> <j....@gmail.com> wrote:
>> >> > On Tue, Apr 13, 2010 at 10:34 AM, Brian Mearns <bm...@ieee.org>
>> >> > wrote:
>> >> >>
>> >> >> I'd like to use stronger and correlated ETag, namely the hash of the
>> >> >> content being served. Obviously it's a drag to do this in-line, so
>> >> >> I'm
>> >> >> planning an automated task to generate the ETag values and store
>> >> >> them
>> >> >> on the server. Is there any way I can get httpd to grab these stored
>> >> >> values for use in the Etag header? I'm flexible on how I store them:
>> >> >> in a database, in one large file, each in its own file named
>> >> >> according
>> >> >> to the resource, etc.
>> >> >>
>> >> >> Any ideas?
>> >> >>
>> >> >> Thanks,
>> >> >> -Brian
>> >> >>
>> >> >> --
>> >> >> Feel free to contact me using PGP Encryption:
>> >> >> Key Id: 0x3AA70848
>> >> >> Available from: http://keys.gnupg.net
>> >> >>
>> >> >>
>> >> >> ---------------------------------------------------------------------
>> >> >> The official User-To-User support forum of the Apache HTTP Server
>> >> >> Project.
>> >> >> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> >> >> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> >> >>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> >> >> For additional commands, e-mail: users-help@httpd.apache.org
>> >> >>
>> >> >
>> >> > I have some "static" content that's actually built dynamically on the
>> >> > server
>> >> > (it's just a concatenated, minified JS or CSS file), and therefore
>> >> > can't
>> >> > use
>> >> > Apache's default etags/expires headers which I believe only apply to
>> >> > real
>> >> > files, so I do the same thing you're suggesting, in php.
>> >> > I would much rather let Apache take care of this for me, but my
>> >> > obsessive
>> >> > and orderly mind demands that I keep the Javascript and CSS that
>> >> > applies
>> >> > to
>> >> > different parts of the site in different files, and my background in
>> >> > high-load high-availability web-serving makes me want to keep the
>> >> > number
>> >> > of
>> >> > http requests down.
>> >> > So my question to you is, what is your reason for wanting to do this,
>> >> > and
>> >> > how would you implement if it did exist?  It's pretty trivial to do
>> >> > it
>> >> > with
>> >> > a scripting language that can alter response headers, if in fact it's
>> >> > really
>> >> > necessary..
>> >>
>> >> The reason is just to optimize caching. I guess the ETag doesn't
>> >> really need to be any stronger than the built-in, but I would like it
>> >> to be correlated, meaning if the content hasn't actually changed, or
>> >> has changed and then changed back, it will have the same ETag even
>> >> though the last-mod time is different.
>> >>
>> >> I'm not sure exactly what you mean by how I would implement it. In
>> >> terms of generating the ETag values? For true static content, I would
>> >> just hash the file. For PHP, for instance, I would filter it through
>> >> `php -w` first, and hash the result. Like I said, I'm not sure exactly
>> >> how I will store the generated values, it depends on how I'm actually
>> >> getting the values in the headers. I would use either a cron job or a
>> >> publishing-script to update the stored ETags.
>> >>
>> >> I have done this before in PHP, but I'd hate to have to serve static
>> >> content through a wrapper PHP script just to put an ETag header in
>> >> there.
>> >>
>> >> Thanks,
>> >> -Brian
>> >>
>> >>
>> >> --
>> >> Feel free to contact me using PGP Encryption:
>> >> Key Id: 0x3AA70848
>> >> Available from: http://keys.gnupg.net
>> >>
>> >> ---------------------------------------------------------------------
>> >> The official User-To-User support forum of the Apache HTTP Server
>> >> Project.
>> >> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> >> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> >>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> >> For additional commands, e-mail: users-help@httpd.apache.org
>> >>
>> >
>> > check out http://httpd.apache.org/docs/2.0/mod/core.html#fileetag
>> > If you can't get what you want with that, my personal opinion is that
>> > the
>> > performance gained by your request would not justify the amount of time
>> > required to develop it.
>>
>> Thanks for the reference. The FileEtag directive is not as strong as
>> what I'm looking for. I understand your sentiment about it not being
>> worth the effort: but development effort is temporary, performance
>> improvements are forever =).
>>
>> -Brian
>>
>> --
>> Feel free to contact me using PGP Encryption:
>> Key Id: 0x3AA70848
>> Available from: http://keys.gnupg.net
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>
> Of course performance is everything.
> Every time a user requests a resource, this is what you want in your
> proposed scenario:
> calculate hash of file based on _file contents_ -> compare it to the user's
> declared e-tag -> send either 200 or 304 response
> this is what's currently happening:
> calculate hash of file based on _file attributes_ -> compare it to user's
> e-tag/expires data -> send response
> It seems to me that right off the bat you're losing performance because it
> will certainly take longer to pull the full contents of the file and hash
> that, rather than just using the attributes of the file to compute the
> e-tag.
> The only scenario in which your method performs better than the standard
> Apache e-tag implementation is when a file is modified and later restored to
> its original state between the time the user accesses that resource a first
> and second time.  If I was an engineer in your group I'd ask to see some
> data to prove this happens often enough to make up for the initial
> performance loss.
> Does that make sense, am I missing any details or anything?

A small but important detail: I'm hashing the content off-line, so my
proposed process looks like this (when a request comes in):
read tag from file/database/etc -> compare to submitted etag -> send response.

So yes, it will be primarily of benefit when the content changes and
changes back, but it should (in theory) always be a bit faster than
the default, since there are no attributes to check and no hash to
perform as far as apache is concerned.

This is a personal web server, there's no group or any other
bureaucracy for me to worry about =). I'm fine-tuning it as a hobby.

-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://keys.gnupg.net

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Custom ETags

Posted by Jonathan Zuckerman <j....@gmail.com>.
On Tue, Apr 13, 2010 at 1:20 PM, Brian Mearns <me...@gmail.com> wrote:

> On Tue, Apr 13, 2010 at 1:13 PM, Jonathan Zuckerman
> <j....@gmail.com> wrote:
> >
> >
> > On Tue, Apr 13, 2010 at 12:13 PM, Brian Mearns <me...@gmail.com>
> wrote:
> >>
> >> On Tue, Apr 13, 2010 at 10:49 AM, Jonathan Zuckerman
> >> <j....@gmail.com> wrote:
> >> > On Tue, Apr 13, 2010 at 10:34 AM, Brian Mearns <bm...@ieee.org>
> wrote:
> >> >>
> >> >> I'd like to use stronger and correlated ETag, namely the hash of the
> >> >> content being served. Obviously it's a drag to do this in-line, so
> I'm
> >> >> planning an automated task to generate the ETag values and store them
> >> >> on the server. Is there any way I can get httpd to grab these stored
> >> >> values for use in the Etag header? I'm flexible on how I store them:
> >> >> in a database, in one large file, each in its own file named
> according
> >> >> to the resource, etc.
> >> >>
> >> >> Any ideas?
> >> >>
> >> >> Thanks,
> >> >> -Brian
> >> >>
> >> >> --
> >> >> Feel free to contact me using PGP Encryption:
> >> >> Key Id: 0x3AA70848
> >> >> Available from: http://keys.gnupg.net
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> The official User-To-User support forum of the Apache HTTP Server
> >> >> Project.
> >> >> See <URL:http://httpd.apache.org/userslist.html> for more info.
> >> >> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> >> >>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> >> >> For additional commands, e-mail: users-help@httpd.apache.org
> >> >>
> >> >
> >> > I have some "static" content that's actually built dynamically on the
> >> > server
> >> > (it's just a concatenated, minified JS or CSS file), and therefore
> can't
> >> > use
> >> > Apache's default etags/expires headers which I believe only apply to
> >> > real
> >> > files, so I do the same thing you're suggesting, in php.
> >> > I would much rather let Apache take care of this for me, but my
> >> > obsessive
> >> > and orderly mind demands that I keep the Javascript and CSS that
> applies
> >> > to
> >> > different parts of the site in different files, and my background in
> >> > high-load high-availability web-serving makes me want to keep the
> number
> >> > of
> >> > http requests down.
> >> > So my question to you is, what is your reason for wanting to do this,
> >> > and
> >> > how would you implement if it did exist?  It's pretty trivial to do it
> >> > with
> >> > a scripting language that can alter response headers, if in fact it's
> >> > really
> >> > necessary..
> >>
> >> The reason is just to optimize caching. I guess the ETag doesn't
> >> really need to be any stronger than the built-in, but I would like it
> >> to be correlated, meaning if the content hasn't actually changed, or
> >> has changed and then changed back, it will have the same ETag even
> >> though the last-mod time is different.
> >>
> >> I'm not sure exactly what you mean by how I would implement it. In
> >> terms of generating the ETag values? For true static content, I would
> >> just hash the file. For PHP, for instance, I would filter it through
> >> `php -w` first, and hash the result. Like I said, I'm not sure exactly
> >> how I will store the generated values, it depends on how I'm actually
> >> getting the values in the headers. I would use either a cron job or a
> >> publishing-script to update the stored ETags.
> >>
> >> I have done this before in PHP, but I'd hate to have to serve static
> >> content through a wrapper PHP script just to put an ETag header in
> >> there.
> >>
> >> Thanks,
> >> -Brian
> >>
> >>
> >> --
> >> Feel free to contact me using PGP Encryption:
> >> Key Id: 0x3AA70848
> >> Available from: http://keys.gnupg.net
> >>
> >> ---------------------------------------------------------------------
> >> The official User-To-User support forum of the Apache HTTP Server
> Project.
> >> See <URL:http://httpd.apache.org/userslist.html> for more info.
> >> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> >>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> >> For additional commands, e-mail: users-help@httpd.apache.org
> >>
> >
> > check out http://httpd.apache.org/docs/2.0/mod/core.html#fileetag
> > If you can't get what you want with that, my personal opinion is that the
> > performance gained by your request would not justify the amount of time
> > required to develop it.
>
> Thanks for the reference. The FileEtag directive is not as strong as
> what I'm looking for. I understand your sentiment about it not being
> worth the effort: but development effort is temporary, performance
> improvements are forever =).
>
> -Brian
>
> --
> Feel free to contact me using PGP Encryption:
> Key Id: 0x3AA70848
> Available from: http://keys.gnupg.net
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
Of course performance is everything.

Every time a user requests a resource, this is what you want in your
proposed scenario:
calculate hash of file based on _file contents_ -> compare it to the user's
declared e-tag -> send either 200 or 304 response

this is what's currently happening:
calculate hash of file based on _file attributes_ -> compare it to user's
e-tag/expires data -> send response

It seems to me that right off the bat you're losing performance because it
will certainly take longer to pull the full contents of the file and hash
that, rather than just using the attributes of the file to compute the
e-tag.

The only scenario in which your method performs better than the standard
Apache e-tag implementation is when a file is modified and later restored to
its original state between the time the user accesses that resource a first
and second time.  If I was an engineer in your group I'd ask to see some
data to prove this happens often enough to make up for the initial
performance loss.

Does that make sense, am I missing any details or anything?

Re: [users@httpd] Custom ETags

Posted by Brian Mearns <me...@gmail.com>.
On Tue, Apr 13, 2010 at 1:13 PM, Jonathan Zuckerman
<j....@gmail.com> wrote:
>
>
> On Tue, Apr 13, 2010 at 12:13 PM, Brian Mearns <me...@gmail.com> wrote:
>>
>> On Tue, Apr 13, 2010 at 10:49 AM, Jonathan Zuckerman
>> <j....@gmail.com> wrote:
>> > On Tue, Apr 13, 2010 at 10:34 AM, Brian Mearns <bm...@ieee.org> wrote:
>> >>
>> >> I'd like to use stronger and correlated ETag, namely the hash of the
>> >> content being served. Obviously it's a drag to do this in-line, so I'm
>> >> planning an automated task to generate the ETag values and store them
>> >> on the server. Is there any way I can get httpd to grab these stored
>> >> values for use in the Etag header? I'm flexible on how I store them:
>> >> in a database, in one large file, each in its own file named according
>> >> to the resource, etc.
>> >>
>> >> Any ideas?
>> >>
>> >> Thanks,
>> >> -Brian
>> >>
>> >> --
>> >> Feel free to contact me using PGP Encryption:
>> >> Key Id: 0x3AA70848
>> >> Available from: http://keys.gnupg.net
>> >>
>> >> ---------------------------------------------------------------------
>> >> The official User-To-User support forum of the Apache HTTP Server
>> >> Project.
>> >> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> >> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> >>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> >> For additional commands, e-mail: users-help@httpd.apache.org
>> >>
>> >
>> > I have some "static" content that's actually built dynamically on the
>> > server
>> > (it's just a concatenated, minified JS or CSS file), and therefore can't
>> > use
>> > Apache's default etags/expires headers which I believe only apply to
>> > real
>> > files, so I do the same thing you're suggesting, in php.
>> > I would much rather let Apache take care of this for me, but my
>> > obsessive
>> > and orderly mind demands that I keep the Javascript and CSS that applies
>> > to
>> > different parts of the site in different files, and my background in
>> > high-load high-availability web-serving makes me want to keep the number
>> > of
>> > http requests down.
>> > So my question to you is, what is your reason for wanting to do this,
>> > and
>> > how would you implement if it did exist?  It's pretty trivial to do it
>> > with
>> > a scripting language that can alter response headers, if in fact it's
>> > really
>> > necessary..
>>
>> The reason is just to optimize caching. I guess the ETag doesn't
>> really need to be any stronger than the built-in, but I would like it
>> to be correlated, meaning if the content hasn't actually changed, or
>> has changed and then changed back, it will have the same ETag even
>> though the last-mod time is different.
>>
>> I'm not sure exactly what you mean by how I would implement it. In
>> terms of generating the ETag values? For true static content, I would
>> just hash the file. For PHP, for instance, I would filter it through
>> `php -w` first, and hash the result. Like I said, I'm not sure exactly
>> how I will store the generated values, it depends on how I'm actually
>> getting the values in the headers. I would use either a cron job or a
>> publishing-script to update the stored ETags.
>>
>> I have done this before in PHP, but I'd hate to have to serve static
>> content through a wrapper PHP script just to put an ETag header in
>> there.
>>
>> Thanks,
>> -Brian
>>
>>
>> --
>> Feel free to contact me using PGP Encryption:
>> Key Id: 0x3AA70848
>> Available from: http://keys.gnupg.net
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>
> check out http://httpd.apache.org/docs/2.0/mod/core.html#fileetag
> If you can't get what you want with that, my personal opinion is that the
> performance gained by your request would not justify the amount of time
> required to develop it.

Thanks for the reference. The FileEtag directive is not as strong as
what I'm looking for. I understand your sentiment about it not being
worth the effort: but development effort is temporary, performance
improvements are forever =).

-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://keys.gnupg.net

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Custom ETags

Posted by Jonathan Zuckerman <j....@gmail.com>.
On Tue, Apr 13, 2010 at 12:13 PM, Brian Mearns <me...@gmail.com> wrote:

> On Tue, Apr 13, 2010 at 10:49 AM, Jonathan Zuckerman
> <j....@gmail.com> wrote:
> > On Tue, Apr 13, 2010 at 10:34 AM, Brian Mearns <bm...@ieee.org> wrote:
> >>
> >> I'd like to use stronger and correlated ETag, namely the hash of the
> >> content being served. Obviously it's a drag to do this in-line, so I'm
> >> planning an automated task to generate the ETag values and store them
> >> on the server. Is there any way I can get httpd to grab these stored
> >> values for use in the Etag header? I'm flexible on how I store them:
> >> in a database, in one large file, each in its own file named according
> >> to the resource, etc.
> >>
> >> Any ideas?
> >>
> >> Thanks,
> >> -Brian
> >>
> >> --
> >> Feel free to contact me using PGP Encryption:
> >> Key Id: 0x3AA70848
> >> Available from: http://keys.gnupg.net
> >>
> >> ---------------------------------------------------------------------
> >> The official User-To-User support forum of the Apache HTTP Server
> Project.
> >> See <URL:http://httpd.apache.org/userslist.html> for more info.
> >> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> >>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> >> For additional commands, e-mail: users-help@httpd.apache.org
> >>
> >
> > I have some "static" content that's actually built dynamically on the
> server
> > (it's just a concatenated, minified JS or CSS file), and therefore can't
> use
> > Apache's default etags/expires headers which I believe only apply to real
> > files, so I do the same thing you're suggesting, in php.
> > I would much rather let Apache take care of this for me, but my obsessive
> > and orderly mind demands that I keep the Javascript and CSS that applies
> to
> > different parts of the site in different files, and my background in
> > high-load high-availability web-serving makes me want to keep the number
> of
> > http requests down.
> > So my question to you is, what is your reason for wanting to do this, and
> > how would you implement if it did exist?  It's pretty trivial to do it
> with
> > a scripting language that can alter response headers, if in fact it's
> really
> > necessary..
>
> The reason is just to optimize caching. I guess the ETag doesn't
> really need to be any stronger than the built-in, but I would like it
> to be correlated, meaning if the content hasn't actually changed, or
> has changed and then changed back, it will have the same ETag even
> though the last-mod time is different.
>
> I'm not sure exactly what you mean by how I would implement it. In
> terms of generating the ETag values? For true static content, I would
> just hash the file. For PHP, for instance, I would filter it through
> `php -w` first, and hash the result. Like I said, I'm not sure exactly
> how I will store the generated values, it depends on how I'm actually
> getting the values in the headers. I would use either a cron job or a
> publishing-script to update the stored ETags.
>
> I have done this before in PHP, but I'd hate to have to serve static
> content through a wrapper PHP script just to put an ETag header in
> there.
>
> Thanks,
> -Brian
>
>
> --
> Feel free to contact me using PGP Encryption:
> Key Id: 0x3AA70848
> Available from: http://keys.gnupg.net
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
check out http://httpd.apache.org/docs/2.0/mod/core.html#fileetag

If you can't get what you want with that, my personal opinion is that the
performance gained by your request would not justify the amount of time
required to develop it.

Re: [users@httpd] Custom ETags

Posted by Brian Mearns <me...@gmail.com>.
On Tue, Apr 13, 2010 at 10:49 AM, Jonathan Zuckerman
<j....@gmail.com> wrote:
> On Tue, Apr 13, 2010 at 10:34 AM, Brian Mearns <bm...@ieee.org> wrote:
>>
>> I'd like to use stronger and correlated ETag, namely the hash of the
>> content being served. Obviously it's a drag to do this in-line, so I'm
>> planning an automated task to generate the ETag values and store them
>> on the server. Is there any way I can get httpd to grab these stored
>> values for use in the Etag header? I'm flexible on how I store them:
>> in a database, in one large file, each in its own file named according
>> to the resource, etc.
>>
>> Any ideas?
>>
>> Thanks,
>> -Brian
>>
>> --
>> Feel free to contact me using PGP Encryption:
>> Key Id: 0x3AA70848
>> Available from: http://keys.gnupg.net
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>
> I have some "static" content that's actually built dynamically on the server
> (it's just a concatenated, minified JS or CSS file), and therefore can't use
> Apache's default etags/expires headers which I believe only apply to real
> files, so I do the same thing you're suggesting, in php.
> I would much rather let Apache take care of this for me, but my obsessive
> and orderly mind demands that I keep the Javascript and CSS that applies to
> different parts of the site in different files, and my background in
> high-load high-availability web-serving makes me want to keep the number of
> http requests down.
> So my question to you is, what is your reason for wanting to do this, and
> how would you implement if it did exist?  It's pretty trivial to do it with
> a scripting language that can alter response headers, if in fact it's really
> necessary..

The reason is just to optimize caching. I guess the ETag doesn't
really need to be any stronger than the built-in, but I would like it
to be correlated, meaning if the content hasn't actually changed, or
has changed and then changed back, it will have the same ETag even
though the last-mod time is different.

I'm not sure exactly what you mean by how I would implement it. In
terms of generating the ETag values? For true static content, I would
just hash the file. For PHP, for instance, I would filter it through
`php -w` first, and hash the result. Like I said, I'm not sure exactly
how I will store the generated values, it depends on how I'm actually
getting the values in the headers. I would use either a cron job or a
publishing-script to update the stored ETags.

I have done this before in PHP, but I'd hate to have to serve static
content through a wrapper PHP script just to put an ETag header in
there.

Thanks,
-Brian


-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://keys.gnupg.net

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Custom ETags

Posted by Jonathan Zuckerman <j....@gmail.com>.
On Tue, Apr 13, 2010 at 10:34 AM, Brian Mearns <bm...@ieee.org> wrote:

> I'd like to use stronger and correlated ETag, namely the hash of the
> content being served. Obviously it's a drag to do this in-line, so I'm
> planning an automated task to generate the ETag values and store them
> on the server. Is there any way I can get httpd to grab these stored
> values for use in the Etag header? I'm flexible on how I store them:
> in a database, in one large file, each in its own file named according
> to the resource, etc.
>
> Any ideas?
>
> Thanks,
> -Brian
>
> --
> Feel free to contact me using PGP Encryption:
> Key Id: 0x3AA70848
> Available from: http://keys.gnupg.net
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
I have some "static" content that's actually built dynamically on the server
(it's just a concatenated, minified JS or CSS file), and therefore can't use
Apache's default etags/expires headers which I believe only apply to real
files, so I do the same thing you're suggesting, in php.
I would much rather let Apache take care of this for me, but my obsessive
and orderly mind demands that I keep the Javascript and CSS that applies to
different parts of the site in different files, and my background in
high-load high-availability web-serving makes me want to keep the number of
http requests down.

So my question to you is, what is your reason for wanting to do this, and
how would you implement if it did exist?  It's pretty trivial to do it with
a scripting language that can alter response headers, if in fact it's really
necessary..

Re: [users@httpd] Custom ETags

Posted by Brian Mearns <me...@gmail.com>.
On Tue, Apr 13, 2010 at 4:50 PM, Florian S. <fl...@gmx.net> wrote:
> Am Dienstag, den 13.04.2010, 10:34 -0400 schrieb Brian Mearns:
>> I'd like to use stronger and correlated ETag, namely the hash of the
>> content being served. Obviously it's a drag to do this in-line, so I'm
>> planning an automated task to generate the ETag values and store them
>> on the server. Is there any way I can get httpd to grab these stored
>> values for use in the Etag header? I'm flexible on how I store them:
>> in a database, in one large file, each in its own file named according
>> to the resource, etc.
>>
>> Any ideas?
>>
>> Thanks,
>> -Brian
>>
>
> Hi,
>
> Here a short presentation of how I would face this problem:
> I found a nice & powerful way of including external scripts depending on
> URL/I: RewriteMap. I think its performance is sufficient, since the
> process gets spawned only once and the stdio-stuff happens only.
> Text-Databases are supported, too. The output (the ETag?) could be
> stored in a Envar with a corresponding RewriteRule (E-flag). Then you
> can do a few checks and/or use 'Header set ETag new_tag env=new_tag' or
> something similiar.
>
> Not tested at all & sounds strange, but may be a starting point.
>
> Regards:
>        Florian
>
[snip]

Thanks, Florian. That's a pretty clever idea, definitely something
I'll add to my bag of tricks. I don't think it will help me in this
case, though, as it occurs to me that just setting the ETag header
isn't enough, I have to get Apache to act on it (honor conditional
requests). It sounds like the only real Apache solution is to create a
module to do what I want, but that's probably not going to happen
anytime soon.

In the mean time, I probably will just throw together a PHP script
through which all the appropriate resources are accessed. It can read
the Etags from the file/database and decide what to do with
conditional responses.

Thanks for the great idea!
-Brian


-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://keys.gnupg.net

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Custom ETags

Posted by "Florian S." <fl...@gmx.net>.
Am Dienstag, den 13.04.2010, 10:34 -0400 schrieb Brian Mearns:
> I'd like to use stronger and correlated ETag, namely the hash of the
> content being served. Obviously it's a drag to do this in-line, so I'm
> planning an automated task to generate the ETag values and store them
> on the server. Is there any way I can get httpd to grab these stored
> values for use in the Etag header? I'm flexible on how I store them:
> in a database, in one large file, each in its own file named according
> to the resource, etc.
> 
> Any ideas?
> 
> Thanks,
> -Brian
> 

Hi,

Here a short presentation of how I would face this problem:
I found a nice & powerful way of including external scripts depending on
URL/I: RewriteMap. I think its performance is sufficient, since the
process gets spawned only once and the stdio-stuff happens only.
Text-Databases are supported, too. The output (the ETag?) could be
stored in a Envar with a corresponding RewriteRule (E-flag). Then you
can do a few checks and/or use 'Header set ETag new_tag env=new_tag' or
something similiar.

Not tested at all & sounds strange, but may be a starting point.

Regards:
	Florian


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org