Changeset 12504


Ignore:
Timestamp:
02/23/10 14:34:45 (12 years ago)
Author:
Mark Evenson
Message:

Implement HTTP HEAD Last-Modified checking for ZipCache? objects.

Since it seems that no Sun-derived JVM ever invalidates its cache of
URLConnection objects, we have to check for modification "manually".
This implementation is "better than nothing", but not expected to be
especially robust. Most notably, this implementation does not attempt
to use http proxies if they have been specified to the JVM by the
'http.proxy' system property.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/ZipCache.java

    r12451 r12504  
    3333package org.armedbear.lisp;
    3434
    35 
     35import org.armedbear.lisp.util.HttpHead;
    3636import static org.armedbear.lisp.Lisp.*;
    3737
    3838import java.io.File;
    39 import java.io.InputStream;
    4039import java.io.IOException;
    4140import java.net.JarURLConnection;
     
    4342import java.net.URL;
    4443import java.net.URLConnection;
    45 import java.util.Enumeration;
     44import java.text.ParseException;
     45import java.text.SimpleDateFormat;
     46import java.util.Date;
    4647import java.util.HashMap;
    4748import java.util.zip.ZipException;
    4849import java.util.zip.ZipFile;
    49 import java.util.zip.ZipEntry;
    5050
    5151/**
     
    6868    // out, not allowing ZipFile.close() to succeed until that count
    6969    // has been reduced to 1 or the finalizer is executing.
    70     // Unfortunately the relatively simple strategy of extended
     70    // Unfortunately the relatively simple strategy of extending
    7171    // ZipFile via a CachedZipFile does not work because there is not
    7272    // a null arg constructor for ZipFile.
     
    101101        return get(Pathname.makeURL(arg));
    102102    }
     103
     104    static final SimpleDateFormat RFC_1123
     105        = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
    103106
    104107    synchronized public static ZipFile get(final URL url) {
     
    146149                    }
    147150                }
    148             } else {
     151            } else if (url.getProtocol().equals("http")) {
    149152                // Unfortunately, the Apple JDK under OS X doesn't do
    150153                // HTTP HEAD requests, instead refetching the entire
    151                 // resource, so the following code is a waste.  I assume
    152                 // this is the case in all Sun-dervied JVMs. We'll have
    153                 // to implement a custom HTTP lastModified checker.
    154 
    155                 // URLConnection connection;
    156                 // try {
    157                 //     connection = url.openConnection();
    158                 // } catch (IOException ex) {
    159                 //     Debug.trace("Failed to open "
    160                 //                 + "'" + url + "'");
    161                 //     return null;
    162                 // }
    163                 // long current = connection.getLastModified();
    164                 // if (current > entry.lastModified) {
    165                 //     try {
    166                 //         entry.file.close();
    167                 //     } catch (IOException ex) {}
    168                 //     entry = fetchURL(url, false);
    169                 // }
     154                // resource, and I assume this is the case in all
     155                // Sun-derived JVMs.  So, we use a custom HEAD
     156                // implementation only looking for Last-Modified
     157                // headers, which if we don't find, we give up and
     158                // refetch the resource.n
     159                String dateString = HttpHead.get(url, "Last-Modified");
     160                Date date = null;
     161                try {
     162                    date = RFC_1123.parse(dateString);
     163                    long current = date.getTime();
     164                    if (current > entry.lastModified) {
     165                        entry = fetchURL(url, false);
     166                        zipCache.put(url, entry);
     167                    }
     168                } catch (ParseException e) {
     169                   Debug.trace("Failed to parse HTTP Last-Modified field: " + e);
     170                   entry = fetchURL(url, false);
     171                   zipCache.put(url, entry);
     172                }
     173           } else {
     174                entry = fetchURL(url, false);
     175                zipCache.put(url, entry);
    170176            }
    171177        } else {
Note: See TracChangeset for help on using the changeset viewer.