Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3eeceed authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

add conditional use of Gzip in LightReadFolderRemoteOperation

parent 14d81aba
Loading
Loading
Loading
Loading
+24 −22
Original line number Diff line number Diff line
@@ -57,27 +57,21 @@ public class LightReadFolderRemoteOperation extends RemoteOperation {
    private String mRemotePath;
    private ArrayList<Object> mFolderAndFiles;
    private int depth;
    /**
     * Constructor
     *
     * @param remotePath Remote path of the file.
     */
    public LightReadFolderRemoteOperation(String remotePath) {
        this(remotePath, DavConstants.DEPTH_1);
    }
    private boolean allowGzip;

    /**
     * Constructor
     * @param remotePath remothe path of folder
     * @param depth depth to reach. Value should be in DavConstants (DEPTH_0, DEPTH_1 or DEPTH_INFINITY). DEPTH_0 by default
     */
    public LightReadFolderRemoteOperation(String remotePath, int depth){
    public LightReadFolderRemoteOperation(String remotePath, int depth, boolean allowGzip){
        mRemotePath = remotePath;
        if(depth == DavConstants.DEPTH_0 || depth == DavConstants.DEPTH_1 || depth == DavConstants.DEPTH_INFINITY) {
            this.depth = depth;
        }else{
            this.depth = DavConstants.DEPTH_0;
        }
        this.allowGzip = allowGzip;
    }


@@ -90,16 +84,22 @@ public class LightReadFolderRemoteOperation extends RemoteOperation {
    protected RemoteOperationResult run(OwnCloudClient client) {
        RemoteOperationResult result = null;
        PropFindMethod query = null;

        String userAgent ="";
        try {
            // remote request
            if(allowGzip){
                query = new GzipedPropfind(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
                    WebdavUtils.getMinimumPropSet(),    // PropFind Properties
                    this.depth);
            query.setRequestHeader("Accept-Encoding", "deflate,gzip");
            
                query.setRequestHeader("Accept-Encoding", "gzip");
                userAgent = "gzipUserAgent";
            }else{
                query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
                        WebdavUtils.getAllPropSet(),    // PropFind Properties
                        this.depth);
            }

            int status = client.executeMethod(query, "gzipUserAgent");
            int status = client.executeMethod(query, userAgent);
            // check and process response
            boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK);
            
@@ -115,14 +115,16 @@ public class LightReadFolderRemoteOperation extends RemoteOperation {
                    result.setData(mFolderAndFiles);
                }
            } else {

                // synchronization failed
                //@THis need to be check!

                if(allowGzip) {
                    GZIPInputStream gzipSteam = null;
                    gzipSteam = new GZIPInputStream(query.getResponseBodyAsStream());
                // synchronization failed
                //client.exhaustResponse(query.getResponseBodyAsStream());
                    client.exhaustGZippedResponse(gzipSteam);
                }else{
                    client.exhaustResponse(query.getResponseBodyAsStream());
                }

                result = new RemoteOperationResult(false, query);
            }
        } catch (Exception e) {