ashishpnd7 / sandrop

Automatically exported from code.google.com/p/sandrop
0 stars 0 forks source link

enable/disable browser cache headers #30

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
package org.sandrop.webscarab.plugin.proxy;

import java.io.IOException;
import org.sandrop.webscarab.httpclient.HTTPClient;
import org.sandrop.webscarab.model.Preferences;
import org.sandrop.webscarab.model.Request;
import org.sandrop.webscarab.model.Response;

public class BrowserCache extends ProxyPlugin {

    private boolean _enabled = false;

    public BrowserCache() {
        parseProperties();
    }

    public void parseProperties() {
        String prop = "BrowserCache.enabled";
        _enabled = Preferences.getPreferenceBoolean(prop, false);
    }

    public String getPluginName() {
        return new String("Browser Cache");
    }

    public void setEnabled(boolean bool) {
        _enabled = bool;
        String prop = "BrowserCache.enabled";
        Preferences.setPreference(prop,Boolean.toString(bool));
    }

    public boolean getEnabled() {
        return _enabled;
    }

    public HTTPClient getProxyPlugin(HTTPClient in) {
        return new Plugin(in);
    }    

    private class Plugin implements HTTPClient {

        private HTTPClient _in;

        public Plugin(HTTPClient in) {
            _in = in;
        }

        public Response fetchResponse(Request request) throws IOException {
            if (_enabled) {
                // we could be smarter about this, and keep a record of the pages that we 
                // have seen so far, and only remove headers for those that we have not?
                request.deleteHeader("ETag");
                request.deleteHeader("If-Modified-Since");
                request.deleteHeader("If-None-Match");
            }
            return _in.fetchResponse(request);
        }

    }

}

Original issue reported on code.google.com by supp.san...@gmail.com on 4 Jul 2012 at 6:22

GoogleCodeExporter commented 9 years ago

Original comment by supp.san...@gmail.com on 9 Jul 2012 at 7:45