1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Refactor interceptors and include move headers

This commit is contained in:
davigonz 2018-07-02 15:39:15 +02:00
parent ed073d6db0
commit 1d80067f85
18 changed files with 127 additions and 264 deletions

View File

@ -25,20 +25,9 @@ package com.owncloud.android.lib.common.authentication;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.http.interceptors.BarearAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.BasicAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor;
import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor.RequestInterceptor;
import com.owncloud.android.lib.common.http.interceptors.SamlAuthInterceptor;
import com.owncloud.android.lib.common.http.HttpConstants;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Credentials;
public class OwnCloudBasicCredentials implements OwnCloudCredentials {
@ -62,21 +51,13 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials {
@Override
public void applyTo(OwnCloudClient client) {
ArrayList<RequestInterceptor> requestInterceptors = HttpClient.getOkHttpInterceptor().getRequestInterceptors();
// Clear previous basic credentials
for (HttpInterceptor.RequestInterceptor requestInterceptor : requestInterceptors) {
if (requestInterceptor instanceof BasicAuthInterceptor
|| requestInterceptor instanceof BarearAuthInterceptor
|| requestInterceptor instanceof SamlAuthInterceptor) {
requestInterceptors.remove(requestInterceptor);
}
}
HttpClient.deleteHeaderForAllRequests(HttpConstants.BASIC_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.BEARER_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
HttpClient.getOkHttpInterceptor()
.addRequestInterceptor(
new BasicAuthInterceptor(mUsername, mPassword)
);
HttpClient.addHeaderForAllRequests(HttpConstants.BASIC_AUTHORIZATION_HEADER,
Credentials.basic(mUsername, mPassword));
}
@Override
@ -98,5 +79,4 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials {
public boolean authTokenCanBeRefreshed() {
return false;
}
}
}

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2018 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -23,15 +23,9 @@
*/
package com.owncloud.android.lib.common.authentication;
import java.util.ArrayList;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.http.interceptors.BarearAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.BasicAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor;
import com.owncloud.android.lib.common.http.interceptors.SamlAuthInterceptor;
import com.owncloud.android.lib.common.http.HttpConstants;
public class OwnCloudBearerCredentials implements OwnCloudCredentials {
@ -45,21 +39,12 @@ public class OwnCloudBearerCredentials implements OwnCloudCredentials {
@Override
public void applyTo(OwnCloudClient client) {
// Clear previous credentials
HttpClient.deleteHeaderForAllRequests(HttpConstants.BASIC_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.BEARER_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
final ArrayList<HttpInterceptor.RequestInterceptor> requestInterceptors =
HttpClient.getOkHttpInterceptor().getRequestInterceptors();
// Clear previous basic credentials
for (HttpInterceptor.RequestInterceptor requestInterceptor : requestInterceptors) {
if (requestInterceptor instanceof BasicAuthInterceptor
|| requestInterceptor instanceof BarearAuthInterceptor
|| requestInterceptor instanceof SamlAuthInterceptor) {
requestInterceptors.remove(requestInterceptor);
}
}
HttpClient.getOkHttpInterceptor()
.addRequestInterceptor(new BarearAuthInterceptor(mAccessToken));
HttpClient.addHeaderForAllRequests(HttpConstants.BEARER_AUTHORIZATION_HEADER, mAccessToken);
}
@Override
@ -82,5 +67,4 @@ public class OwnCloudBearerCredentials implements OwnCloudCredentials {
public boolean authTokenCanBeRefreshed() {
return true;
}
}
}

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2018 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -26,12 +26,7 @@ package com.owncloud.android.lib.common.authentication;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.http.interceptors.BarearAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.BasicAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor;
import com.owncloud.android.lib.common.http.interceptors.SamlAuthInterceptor;
import java.util.ArrayList;
import com.owncloud.android.lib.common.http.HttpConstants;
public class OwnCloudCredentialsFactory {
@ -71,16 +66,10 @@ public class OwnCloudCredentialsFactory {
@Override
public void applyTo(OwnCloudClient client) {
ArrayList<HttpInterceptor.RequestInterceptor> requestInterceptors = HttpClient.getOkHttpInterceptor().getRequestInterceptors();
// Clear previous basic credentials
for (HttpInterceptor.RequestInterceptor requestInterceptor : requestInterceptors) {
if (requestInterceptor instanceof BasicAuthInterceptor
|| requestInterceptor instanceof BarearAuthInterceptor
|| requestInterceptor instanceof SamlAuthInterceptor) {
requestInterceptors.remove(requestInterceptor);
}
}
HttpClient.deleteHeaderForAllRequests(HttpConstants.BASIC_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.BEARER_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
}
@Override
@ -104,5 +93,4 @@ public class OwnCloudCredentialsFactory {
return null;
}
}
}
}

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2018 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -25,13 +25,7 @@ package com.owncloud.android.lib.common.authentication;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.http.interceptors.BarearAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.BasicAuthInterceptor;
import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor;
import com.owncloud.android.lib.common.http.interceptors.SamlAuthInterceptor;
import java.util.ArrayList;
import com.owncloud.android.lib.common.http.HttpConstants;
public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
@ -45,20 +39,12 @@ public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
@Override
public void applyTo(OwnCloudClient client) {
final ArrayList<HttpInterceptor.RequestInterceptor> requestInterceptors =
HttpClient.getOkHttpInterceptor().getRequestInterceptors();
// Clear previous credentials
HttpClient.deleteHeaderForAllRequests(HttpConstants.BASIC_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.BEARER_AUTHORIZATION_HEADER);
HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER);
// Clear previous basic credentials
for (HttpInterceptor.RequestInterceptor requestInterceptor : requestInterceptors) {
if (requestInterceptor instanceof BasicAuthInterceptor
|| requestInterceptor instanceof BarearAuthInterceptor
|| requestInterceptor instanceof SamlAuthInterceptor) {
requestInterceptors.remove(requestInterceptor);
}
}
HttpClient.getOkHttpInterceptor()
.addRequestInterceptor(new SamlAuthInterceptor(mSessionCookie));
HttpClient.addHeaderForAllRequests(HttpConstants.COOKIE_HEADER, mSessionCookie);
}
@Override
@ -81,5 +67,4 @@ public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials {
public boolean authTokenCanBeRefreshed() {
return false;
}
}
}

View File

@ -25,19 +25,19 @@
package com.owncloud.android.lib.common.http;
import android.content.Context;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.owncloud.android.lib.BuildConfig;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.http.interceptors.HttpInterceptor;
import com.owncloud.android.lib.common.http.interceptors.UserAgentInterceptor;
import com.owncloud.android.lib.common.http.interceptors.RequestHeaderInterceptor;
import com.owncloud.android.lib.common.network.AdvancedX509TrustManager;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
import java.util.Arrays;
import javax.net.ssl.SSLContext;
@ -58,7 +58,6 @@ public class HttpClient {
private static HttpInterceptor sOkHttpInterceptor;
private static Context sContext;
public static void setContext(Context context) {
sContext = context;
}
@ -90,14 +89,10 @@ public class HttpClient {
return sOkHttpClient;
}
public static HttpInterceptor getOkHttpInterceptor() {
private static HttpInterceptor getOkHttpInterceptor() {
if (sOkHttpInterceptor == null) {
sOkHttpInterceptor = new HttpInterceptor()
.addRequestInterceptor(new UserAgentInterceptor(
// TODO Try to get rid of this dependency
OwnCloudClientManagerFactory.getUserAgent()
)
);
sOkHttpInterceptor = new HttpInterceptor();
addHeaderForAllRequests(HttpConstants.USER_AGENT_HEADER, OwnCloudClientManagerFactory.getUserAgent());
}
return sOkHttpInterceptor;
}
@ -118,4 +113,20 @@ public class HttpClient {
}
sOkHttpClient = clientBuilder.build();
}
/**
* Add header that will be included for all the requests from now on
* @param headerName
* @param headerValue
*/
public static void addHeaderForAllRequests(String headerName, String headerValue) {
getOkHttpInterceptor()
.addRequestInterceptor(
new RequestHeaderInterceptor(headerName, headerValue)
);
}
public static void deleteHeaderForAllRequests(String headerName) {
getOkHttpInterceptor().deleteRequestHeaderInterceptor(headerName);
}
}

View File

@ -33,10 +33,10 @@ public class HttpConstants {
*************************************************** HEADERS ***********************************************
***********************************************************************************************************/
/***********************************************************************************************************
*************************************************** HEADERS ***********************************************
***********************************************************************************************************/
public static final String BASIC_AUTHORIZATION_HEADER = "Authorization";
public static final String COOKIE_HEADER = "Cookie";
public static final String BEARER_AUTHORIZATION_HEADER = "Bearer ";
public static final String USER_AGENT_HEADER = "User-Agent";
public static final String IF_MATCH_HEADER = "If-Match";
public static final String IF_NONE_MATCH_HEADER = "If-None-Match";
public static final String CONTENT_TYPE_HEADER = "Content-Type";

View File

@ -1,21 +0,0 @@
package com.owncloud.android.lib.common.http.interceptors;
import okhttp3.Request;
public class BarearAuthInterceptor implements HttpInterceptor.RequestInterceptor {
private static final String AUTHORIZATION_HEADER = "Authorization";
private final String mBarearToken;
public BarearAuthInterceptor(String barearToken) {
this.mBarearToken = barearToken;
}
@Override
public Request intercept(Request request) {
return request
.newBuilder()
.addHeader(AUTHORIZATION_HEADER, "Bearer " + mBarearToken)
.build();
}
}

View File

@ -1,43 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2018 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.common.http.interceptors;
import okhttp3.Credentials;
import okhttp3.Request;
public class BasicAuthInterceptor implements HttpInterceptor.RequestInterceptor {
private static final String AUTHORIZATION_HEADER = "Authorization";
private String mCredentials;
public BasicAuthInterceptor(String username, String password) {
mCredentials = Credentials.basic(username, password);
}
@Override
public Request intercept(Request request) {
return request.newBuilder().addHeader(AUTHORIZATION_HEADER, mCredentials).build();
}
}

View File

@ -65,7 +65,7 @@ public class HttpInterceptor implements Interceptor {
Response intercept(Response response) throws IOException;
}
public HttpInterceptor addRequestInterceptor (RequestInterceptor requestInterceptor) {
public HttpInterceptor addRequestInterceptor(RequestInterceptor requestInterceptor) {
mRequestInterceptors.add(requestInterceptor);
return this;
}
@ -79,7 +79,28 @@ public class HttpInterceptor implements Interceptor {
return mRequestInterceptors;
}
private ArrayList<RequestHeaderInterceptor> getRequestHeaderInterceptors() {
ArrayList<RequestHeaderInterceptor> requestHeaderInterceptors = new ArrayList<>();
for (RequestInterceptor requestInterceptor : mRequestInterceptors) {
if (requestInterceptor instanceof RequestHeaderInterceptor) {
requestHeaderInterceptors.add((RequestHeaderInterceptor) requestInterceptor);
}
}
return requestHeaderInterceptors;
}
public void deleteRequestHeaderInterceptor(String headerName) {
for (RequestInterceptor requestInterceptor : mRequestInterceptors) {
if (requestInterceptor instanceof RequestHeaderInterceptor &&
((RequestHeaderInterceptor) requestInterceptor).getHeaderName().equals(headerName)) {
mRequestInterceptors.remove(requestInterceptor);
}
}
}
public ArrayList<ResponseInterceptor> getResponseInterceptors() {
return mResponseInterceptors;
}
}
}

View File

@ -0,0 +1,27 @@
package com.owncloud.android.lib.common.http.interceptors;
import okhttp3.Request;
public class RequestHeaderInterceptor implements HttpInterceptor.RequestInterceptor {
private String mHeaderName;
private String mHeaderValue;
public RequestHeaderInterceptor(String headerName, String headerValue) {
this.mHeaderName = headerName;
this.mHeaderValue = headerValue;
}
@Override
public Request intercept(Request request) {
return request.newBuilder().addHeader(mHeaderName, mHeaderValue).build();
}
public String getHeaderName() {
return mHeaderName;
}
public String getHeaderValue() {
return mHeaderValue;
}
}

View File

@ -1,21 +0,0 @@
package com.owncloud.android.lib.common.http.interceptors;
import java.io.IOException;
import okhttp3.Request;
public class SamlAuthInterceptor implements HttpInterceptor.RequestInterceptor {
private final String mSessionCookie;
public SamlAuthInterceptor(String sessionCookie) {
this.mSessionCookie = sessionCookie;
}
@Override
public Request intercept(Request request) throws IOException {
return request.newBuilder()
.addHeader("Cookie", mSessionCookie)
.build();
}
}

View File

@ -1,42 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2018 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.common.http.interceptors;
import okhttp3.Request;
public class UserAgentInterceptor implements HttpInterceptor.RequestInterceptor {
private static final String USER_AGENT_HEADER = "User-Agent";
private String mUserAgent;
public UserAgentInterceptor(String userAgent) {
mUserAgent = userAgent;
}
@Override
public Request intercept(Request request) {
return request.newBuilder().addHeader(USER_AGENT_HEADER, mUserAgent).build();
}
}

View File

@ -60,8 +60,6 @@ public abstract class HttpBaseMethod {
.build();
}
public void abort() {
mCall.cancel();
}

View File

@ -24,6 +24,7 @@
package com.owncloud.android.lib.common.http.methods.webdav;
import com.owncloud.android.lib.common.http.HttpClient;
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
import java.util.concurrent.TimeUnit;

View File

@ -54,16 +54,13 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
private static final int LAST_CHUNK_TIMEOUT = 900000; //15 mins.
public static final long CHUNK_SIZE = 1024000;
private static final String OC_CHUNKED_HEADER = "OC-Chunked";
private static final String OC_CHUNK_SIZE_HEADER = "OC-Chunk-Size";
private static final String OC_CHUNK_X_OC_MTIME_HEADER = "X-OC-Mtime";
private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName();
private long mTransferId;
public ChunkedUploadRemoteFileOperation(long transferId, String storagePath, String remotePath, String mimeType,
public ChunkedUploadRemoteFileOperation(long transferId, String localPath, String remotePath, String mimeType,
String requiredEtag, String fileLastModifTimestamp) {
super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp);
super(localPath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp);
mTransferId = transferId;
}
@ -92,14 +89,9 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
String uriPrefix = client.getNewUploadsWebDavUri() + FileUtils.PATH_SEPARATOR + String.valueOf(mTransferId);
long totalLength = fileToUpload.length();
long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE);
String chunkSizeStr = String.valueOf(CHUNK_SIZE);
String totalLengthStr = String.valueOf(fileToUpload.length());
for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) {
if (chunkIndex == chunkCount - 1) {
chunkSizeStr = String.valueOf(CHUNK_SIZE * chunkCount - totalLength);
}
mPutMethod = new PutMethod(
HttpUtils.stringUrlToHttpUrl(uriPrefix + FileUtils.PATH_SEPARATOR + chunkIndex)
);
@ -108,10 +100,6 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\"");
}
mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, totalLengthStr);
// mPutMethod.addRequestHeader(OC_CHUNK_X_OC_MTIME_HEADER, mFileLastModifTimestamp);
// ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
// mPutMethod.setRequestEntity(mEntity);
// if (mCancellationRequested.get()) {

View File

@ -34,7 +34,7 @@ public class FileUtils {
private static final String TAG = FileUtils.class.getSimpleName();
public static final String PATH_SEPARATOR = "/";
public static final String FINAl_CHUNKS_FILE = ".file";
public static final String FINAL_CHUNKS_FILE = ".file";
public static String getParentPath(String remotePath) {
String parentPath = new File(remotePath).getParent();

View File

@ -9,8 +9,11 @@ public class MoveRemoteChunksFileOperation extends MoveRemoteFileOperation {
* @param targetRemotePath Remove path desired for the file/folder after moving it.
* @param overwrite
*/
public MoveRemoteChunksFileOperation(String srcRemotePath, String targetRemotePath, boolean overwrite) {
public MoveRemoteChunksFileOperation(String srcRemotePath, String targetRemotePath, boolean overwrite,
String fileLastModifTimestamp, long fileLength) {
super(srcRemotePath, targetRemotePath, overwrite);
isChunkedFile = true;
mFileLastModifTimestamp = fileLastModifTimestamp;
mFileLength = fileLength;
}
}

View File

@ -40,7 +40,6 @@ import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
/**
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
* in the same account.
@ -59,21 +58,23 @@ public class MoveRemoteFileOperation extends RemoteOperation {
private String mSrcRemotePath;
private String mTargetRemotePath;
private boolean mOverwrite;
protected boolean isChunkedFile;
protected String mFileLastModifTimestamp;
protected long mFileLength;
/**
* Constructor.
* <p>
*
* TODO Paths should finish in "/" in the case of folders. ?
*
* @param srcRemotePath Remote path of the file/folder to move.
* @param targetRemotePath Remove path desired for the file/folder after moving it.
* @param targetRemotePath Remote path desired for the file/folder after moving it.
*/
public MoveRemoteFileOperation(
String srcRemotePath, String targetRemotePath, boolean overwrite
) {
public MoveRemoteFileOperation(String srcRemotePath,
String targetRemotePath,
boolean overwrite) {
mSrcRemotePath = srcRemotePath;
mTargetRemotePath = targetRemotePath;
@ -81,7 +82,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
isChunkedFile = false;
}
/**
* Performs the rename operation.
*
@ -121,6 +121,11 @@ public class MoveRemoteFileOperation extends RemoteOperation {
client.getNewFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
mOverwrite);
if (isChunkedFile) {
move.addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, mFileLastModifTimestamp);
move.addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, String.valueOf(mFileLength));
}
move.setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS);
move.setConnectionTimeout(MOVE_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
@ -149,7 +154,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
result = new RemoteOperationResult(e);
Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
result.getLogMessage(), e);
}
return result;