mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Send unique ID header for all requests
This commit is contained in:
		
							parent
							
								
									7627f75aa9
								
							
						
					
					
						commit
						50fda001ce
					
				| @ -25,15 +25,11 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.common; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AccountManager; | ||||
| import android.accounts.AccountsException; | ||||
| import android.accounts.AuthenticatorException; | ||||
| import android.accounts.OperationCanceledException; | ||||
| import android.content.Context; | ||||
| import android.net.Uri; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.accounts.AccountUtils; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; | ||||
| @ -42,6 +38,7 @@ import com.owncloud.android.lib.common.http.HttpConstants; | ||||
| import com.owncloud.android.lib.common.http.methods.HttpBaseMethod; | ||||
| import com.owncloud.android.lib.common.network.RedirectionPath; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| import com.owncloud.android.lib.common.utils.RandomUtils; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| @ -53,6 +50,8 @@ import okhttp3.Cookie; | ||||
| import okhttp3.Headers; | ||||
| import okhttp3.HttpUrl; | ||||
| 
 | ||||
| import static com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID; | ||||
| 
 | ||||
| public class OwnCloudClient extends HttpClient { | ||||
| 
 | ||||
|     public static final String NEW_WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/"; | ||||
| @ -125,6 +124,14 @@ public class OwnCloudClient extends HttpClient { | ||||
|         int status; | ||||
| 
 | ||||
|         do { | ||||
|             // Clean previous request id. This is a bit hacky but is the only way to add request headers in WebDAV | ||||
|             // methods by using Dav4Android | ||||
|             deleteHeaderForAllRequests(OC_X_REQUEST_ID); | ||||
| 
 | ||||
|             // Header to allow tracing requests in apache and ownCloud logs | ||||
|             addHeaderForAllRequests(OC_X_REQUEST_ID, | ||||
|                     RandomUtils.generateRandomString(RandomUtils.generateRandomInteger(20, 200))); | ||||
| 
 | ||||
|             status = method.execute(); | ||||
|             checkFirstRedirection(method); | ||||
|             if(mFollowRedirects && !isIdPRedirection()) { | ||||
|  | ||||
| @ -43,6 +43,7 @@ public class HttpConstants { | ||||
|     public static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; | ||||
|     public static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; | ||||
|     public static final String PARAM_SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header"; | ||||
|     public static final String OC_X_REQUEST_ID = "X-Request-ID"; | ||||
| 
 | ||||
|     /*********************************************************************************************************** | ||||
|      ************************************************ STATUS CODES ********************************************* | ||||
|  | ||||
| @ -1,5 +1,7 @@ | ||||
| package com.owncloud.android.lib.common.utils; | ||||
| 
 | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import java.io.BufferedWriter; | ||||
| import java.io.File; | ||||
| import java.io.FileWriter; | ||||
| @ -7,10 +9,6 @@ import java.io.IOException; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Calendar; | ||||
| 
 | ||||
| import android.os.Environment; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| 
 | ||||
| public class Log_OC { | ||||
|     private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; | ||||
|     private static final String LOG_FOLDER_NAME = "log"; | ||||
|  | ||||
							
								
								
									
										63
									
								
								src/com/owncloud/android/lib/common/utils/RandomUtils.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/com/owncloud/android/lib/common/utils/RandomUtils.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| /* 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.utils; | ||||
| 
 | ||||
| import java.util.Random; | ||||
| 
 | ||||
| /** | ||||
|  * Class with methods to generate random values | ||||
|  * | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| public class RandomUtils { | ||||
| 
 | ||||
|     private static final String CANDIDATECHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + | ||||
|             "1234567890-+/_=.:"; | ||||
| 
 | ||||
|     /** | ||||
|      * @param length the number of random chars to be generated | ||||
|      * | ||||
|      * @return String containing random chars | ||||
|      */ | ||||
|     public static String generateRandomString(int length) { | ||||
|         StringBuilder sb = new StringBuilder(); | ||||
|         Random random = new Random(); | ||||
|         for (int i = 0; i < length; i++) { | ||||
|             sb.append(CANDIDATECHARS.charAt(random.nextInt(CANDIDATECHARS.length()))); | ||||
|         } | ||||
| 
 | ||||
|         return sb.toString(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @param min minimum integer to obtain randomly | ||||
|      * @param max maximum integer to obtain randomly | ||||
|      * @return random integer between min and max | ||||
|      */ | ||||
|     public static int generateRandomInteger(int min, int max) { | ||||
|         Random r = new Random(); | ||||
|         return r.nextInt(max-min) + min; | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user