Walter Lee

how to add Expires header in Sun Java web server 6.1 ?

Tuesday Jul 08, 2008

Sometimes, you would like to add Expires header to all contents in a particular directory, so no cache is allowed in outside browsers.

First of all, it is always better to use web 7.0 because of its better regex matching and httpdate function.

(For Sun internal people, you can look up Sriram's nice write-up on this topic in mailfinder,

Subject : Web Server 7 configuration settings for expires/cache-control/etag

Date: 2008-05-25 16:10

From : Sriram.Natarajan

)

But if you really need this in 6.1, then you can try below <Client..>...</Client> in 6.1:

e.g.  change obj.conf below and add <Client> tags:

apple:/export/home/iws6.1sp9/https-jsp/config> cat obj.conf
# You can edit this file, but comments and formatting changes
# might be lost when the admin server makes changes.

<Object name="default">
AuthTrans fn="match-browser" browser="*MSIE*" ssl-unclean-shutdown="true"
......
Service method="(GET|HEAD|POST)" type="*~magnus-internal/*" fn="send-file"
Service method="TRACE" fn="service-trace"
<Client uri="*/nokeep/*.*">
Output fn="set-variable" insert-srvhdrs="Expires: Thu, 01 Dec 1994 16:00:00 GMT"
</Client>
Error fn="error-j2ee"
AddLog fn="flex-log" name="access"
</Object>

I specified a directory called , /nokeep/ above to test in my env.
I want no cache outside in files inside this /nokeep/ directory.

You can change the above directory name per your requirement.

Also, I just added an old date in my expire header above.
Actually , it can be as simple as -1 because RFC  

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

said,

" The format is an absolute date and time as defined by HTTP-date in section 3.3.1; it MUST be in RFC 1123 date format:

      Expires = "Expires" ":" HTTP-date

An example of its use is

      Expires: Thu, 01 Dec 1994 16:00:00 GMT

      Note: if a response includes a Cache-Control field with the max-
      age directive (see section 14.9.3), that directive overrides the
      Expires field.

HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past ( i.e., "already expired"  ). "

so, any invalid date format, e.g.  -1 , will be considered as in the past as above.

tests:

after the above obj.conf change, then  restart,

apple:/export/home/iws6.1sp9/https-jsp/config> ../stop; ../start

a. test the /nokeep folder to see the new Expires header:

apple:/export/home/iws6.1sp9/https-jsp/config> telnet apple.asia 61907
Trying 129.158.175.16...
Connected to apple.asia.sun.com.
Escape character is '^]'.
GET /nokeep/test.html HTTP/1.1
Host: apple.asia.sun.com:61907

HTTP/1.1 200 OK
Server: Sun-ONE-Web-Server/6.1
Date: Tue, 08 Jul 2008 06:51:25 GMT
Content-length: 5
Content-type: text/html
Last-modified: Tue, 08 Jul 2008 05:30:03 GMT
Etag: "5-4872fb5b"
Accept-ranges: bytes
Expires: Thu, 01 Dec 1994 16:00:00 GMT  ***

b. then test another folder /keep  to see NO such new Expires header:

apple:/export/home/iws6.1sp9/https-jsp/config> telnet apple.asia 61907
Trying 129.158.175.16...
Connected to apple.asia.sun.com.
Escape character is '^]'.
GET /keep/test.html HTTP/1.1
Host: apple.asia.sun.com:61907

HTTP/1.1 200 OK
Server: Sun-ONE-Web-Server/6.1
Date: Tue, 08 Jul 2008 06:52:04 GMT
Content-length: 5
Content-type: text/html
Last-modified: Tue, 08 Jul 2008 05:30:30 GMT
Etag: "5-4872fb76"
Accept-ranges: bytes


However, you can also try other cache-control header in 6.1,
see

http://docs.sun.com/source/817-1831-10/agcontnt.html#wp1003146

However, note the RFC above,
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
"     
Note: if a response includes a Cache-Control field with the max-
age directive (see section 14.9.3), that directive overrides the
Expires field.
"

So, if you are using both max-age and Expires above, then max-age will override the Expires , per RFC.
So, another possibility is just to set max-age=0

e.g. I just added

 No Store and max-age=0 in /nokeep dir from Admin GUI,
 then obj.conf looks like below:

<Object name="default">
.......
Error fn="error-j2ee"
AddLog fn="flex-log" name="access"
<Client uri="*/nokeep/*.*">
Output fn="set-variable" insert-srvhdrs="Expires: Thu, 01 Dec 1994 16:00:00 GMT"
</Client>
</Object>
.......
<Object ppath="/export/home/iws6.1sp9/docs/nokeep/*">
PathCheck fn="set-cache-control" control="no-store,max-age=0"
</Object>

then a telnet test will show:

apple:/export/home/iws6.1sp9/https-jsp/config> telnet apple.asia 61907
Trying 129.158.175.16...
Connected to apple.asia.sun.com.
Escape character is '^]'.
GET /nokeep/test.html HTTP/1.1
Host: apple.asia.sun.com:61907

HTTP/1.1 200 OK
Server: Sun-ONE-Web-Server/6.1
Date: Tue, 08 Jul 2008 07:22:29 GMT
Content-length: 5
Content-type: text/html
Cache-control: no-store,max-age=0  *** 
Last-modified: Tue, 08 Jul 2008 05:30:03 GMT
Etag: "5-4872fb5b"
Accept-ranges: bytes
Expires: Thu, 01 Dec 1994 16:00:00 GMT ***

( note the new "Cache-control: no-store,max-age=0" and Expires header,
and per RFC, max-age will override the Expires field.
  )

and a hit to /keep dir will not have any new headers,
e.g.

apple:/export/home/iws6.1sp9/https-jsp/config> telnet apple.asia 61907
Trying 129.158.175.16...
Connected to apple.asia.sun.com.
Escape character is '^]'.
GET /keep/ HTTP/1.1
Host: apple.asia.sun.com:61907

HTTP/1.1 200 OK
Server: Sun-ONE-Web-Server/6.1
Date: Tue, 08 Jul 2008 07:24:20 GMT
Content-length: 447
Content-type: text/html
Last-modified: Tue, 08 Jul 2008 05:30:30 GMT
Etag: "1bf-4872fb76"
Accept-ranges: bytes

[3] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg