1

キャッシング機能を追加した、NanoHTTPD で構築されたカスタム Web サーバーを使用しています。304 Not Modified 応答をスローする可能性のあるコードの部分は 1 つだけです。

           if(isNotModified(f,header,parms)){// if requested file has not been modified, let's make the browser use it's cache
                Response r= new Response( Response.Status.NOT_MODIFIED, MIME_PLAINTEXT,(String)null,null);
                //r.addHeader(key,val);
                r.addHeader("Last-Modified",""+f.lastModified());//FIXME: doesnt work with wget + prob others as well
                r.addHeader("ETag",f.getPath()+f.lastModified());

                return r;
            }

isNotModified メソッド:

/**
 * check if the file has been modified since the last time client requested it
 * */
public boolean isNotModified(File ff,Properties header, Properties params){
    if(params.getProperty("bust")!= null ||params.getProperty("cachebust")!=null)
        return false; 
    if(ff.getName().endsWith(".pg"))
        return false;
    if(ff.getPath().indexOf("/api/")>=0)
        return false;
    if("no-cache".equalsIgnoreCase(header.getProperty("cache-control")))
        return false;

    String mod = header.getProperty("if-modified-since");//names are converted to lowercase fwiw

    if(mod==null)//this should happen whenever browser sends no if-modified-since
        return false;

    try{
        long l = Long.parseLong(mod);
        if(ff.lastModified()<=l)
            return true;
    }catch(Exception ex){
        ex.printStackTrace();
    }

    return false;
}

何らかの理由で、ヘッダーに If-Modified-Since が指定されていない (またはキャッシュに関連するものがない) にもかかわらず、(少なくとも) Chrome で 304 を取得しています。これにより、ブラウザーはリソースを空の文字列として解釈し、物事を壊します。

4

2 に答える 2