Oops, left something out.

This won't do much good unless you also send back the "Last-Modified" header
with every page that doesn't return a 304.

So change the code a bit so it reads like:

        <CFIF DateCompare(lastModDate, comparisonDate) EQ 1>
                <CFHEADER STATUSCODE="304" STATUSTEXT="Not Modified">
                <CFABORT>
        <CFELSE>
                <CFHEADER NAME="Last-Modified" VALUE="#GetHttpTimeString(Now())#">
        </CFIF>

Again, I haven't really tested much of this, so just make sure the code
works as expected before dropping into production 8^).

--
Mosh Teitelbaum
evoch, LLC
Tel: (301) 625-9191
Fax: (301) 933-3651
Email: [EMAIL PROTECTED]
WWW: http://www.evoch.com/


> -----Original Message-----
> From: Mosh Teitelbaum [mailto:mosh.teitelbaum@;evoch.com]
> Sent: Wednesday, October 23, 2002 9:10 PM
> To: CF-Talk
> Subject: RE: Anybody using manual "304 not modified" response?
>
>
> Susan Rayburn wrote:
> >I'm wondering if anyone is using a manual 304 not modified response with
> >ColdFusion dynamic pages on IIS.  I'd like to pull the last modified date
> >from SQL and pass it to the browser.  If anyone has had luck setting that
> up
> >(or knows of an article explaining how-to) I'd love to see more.
> >
> >I'm interested in using the 304 responses as described in the below
> >discussion.
> >http://www.webmasterworld.com/forum3/6005.htm
>
> Susan:
>
> I've not done this, but your question got me a bit curious and so I looked
> into it a bit more.  First, not all web clients send the If-Modified-Since
> header, so before anything you'd have to check for it's existence.  Cold
> Fusion allows you to access this header via the CGI.HTTP_IF_MODIFIED_SINCE
> variable.  If it exists, its value should be in the format
> specified by RFC
> 1123, for example:
>
>       Sun, 06 Nov 1994 08:49:37 GMT
>
> So, you can parse this date value, and compare it to the last modified
> date/time of your current page/data.  Depending on the result of the
> comparison, you either let the page execute as normal, or you
> return the 304
> response.  So you might use something like the following:
>
>     <CFIF IsDefined("CGI.HTTP_IF_MODIFIED_SINCE")>
>         <CFSET comparisonDate = [convert date to CF timestamp and to local
> time]>
>         <CFSET lastModDate = [get last mod date from file sys or DB]>
>
>         <CFIF DateCompare(lastModDate, comparisonDate) EQ 1>
>             <CFHEADER STATUSCODE="304" STATUSTEXT="Not Modified">
>             <CFABORT>
>         </CFIF>
>     </CFIF>
>
> This doesn't take into account the "If-None-Match" header, also
> discussed in
> RFC 2616, but this is about as far as I've had time to get.  Also, to
> facilitate the logic needed for the first step, "convert date to CF
> timestamp and to local time," I wrote the following UDF (queued at
> cflib.org):
>
> <CFSCRIPT>
> /**
>  * Function that converts HTTPTimeString format to ColdFusion TimeStamp
> format and
>  * optionally converts the time from UTC/GMT to local time.
>  *
>  * @param httpTimeString      A datetime in the format: ddd, dd
> mmm yyyy hh:mm:ss
> GMT. (Required)
>  * @param convertToLocal      A boolean specifying whether
> httpTimeString should
> be converted to local time.  Defaults to false. (Optional)
>  * @return Returns a string in Cold Fusion Time Stamp format.
>  * @author Mosh Teitelbaum ([EMAIL PROTECTED])
>  * @version 1, October 23, 2002
>  */
> function getTimeStamp(httpTimeString) {
>       // Build Time Stamp
>       var tsParts = ListToArray(httpTimeString, " ");
>       var timeStamp = "{ts '" & tsParts[4] & "-" &
> DateFormat("#tsParts[3]#/1/1970", "mm") & "-" & tsParts[2] & " " &
> tsParts[5] & "'}";
>
>       // Convert to local time
>       if ((ArrayLen(Arguments) EQ 2) AND
> (CompareNoCase(Arguments[2], "TRUE") EQ
> 0)) {
>               timeStamp = DateConvert("utc2Local", timeStamp);
>       }
>
>       // Return timeStamp
>       return timeStamp;
> }
> </CFSCRIPT>
>
> After writing and submitting it, I noticed that there is a similar (too
> similar for my tastes, but whatever) UDF that handles the conversion from
> HTTPTimeString to CF TimeStamp but does not handle the conversion from
> UTC/GMT to localtime.  Anyway, your first line of code would now change
> from:
>
>       <CFSET comparisonDate = [convert date to CF timestamp and
> to local time]>
>
> to:
>
>       <CFSET comparisonDate =
> getTimeStamp(CGI.HTTP_IF_MODIFIED_SINCE, True)>
>
> How you get the last modified date is up to you.  You'd have to check, I
> believe, both the file timestamp and the data timestamp.
>
> Good luck and let me know if you take this any further.
>
> --
> Mosh Teitelbaum
> evoch, LLC
> Tel: (301) 625-9191
> Fax: (301) 933-3651
> Email: [EMAIL PROTECTED]
> WWW: http://www.evoch.com/
>
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Reply via email to