mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	
						commit
						45e70f5906
					
				| @ -39,6 +39,7 @@ import org.apache.commons.httpclient.HttpMethodBase; | |||||||
| import org.apache.commons.httpclient.HttpStatus; | import org.apache.commons.httpclient.HttpStatus; | ||||||
| import org.apache.commons.httpclient.HttpVersion; | import org.apache.commons.httpclient.HttpVersion; | ||||||
| import org.apache.commons.httpclient.URI; | import org.apache.commons.httpclient.URI; | ||||||
|  | import org.apache.commons.httpclient.URIException; | ||||||
| import org.apache.commons.httpclient.cookie.CookiePolicy; | import org.apache.commons.httpclient.cookie.CookiePolicy; | ||||||
| import org.apache.commons.httpclient.methods.HeadMethod; | import org.apache.commons.httpclient.methods.HeadMethod; | ||||||
| import org.apache.commons.httpclient.params.HttpMethodParams; | import org.apache.commons.httpclient.params.HttpMethodParams; | ||||||
| @ -90,13 +91,14 @@ public class OwnCloudClient extends HttpClient { | |||||||
|         getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent); |         getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent); | ||||||
|         getParams().setParameter( |         getParams().setParameter( | ||||||
|             PARAM_PROTOCOL_VERSION, |             PARAM_PROTOCOL_VERSION, | ||||||
|         		HttpVersion.HTTP_1_1); |             HttpVersion.HTTP_1_1 | ||||||
|  |         ); | ||||||
| 
 | 
 | ||||||
|         getParams().setCookiePolicy( |         getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); | ||||||
|         		CookiePolicy.IGNORE_COOKIES); |  | ||||||
|         getParams().setParameter( |         getParams().setParameter( | ||||||
|             PARAM_SINGLE_COOKIE_HEADER,             // to avoid problems with some web servers |             PARAM_SINGLE_COOKIE_HEADER,             // to avoid problems with some web servers | ||||||
|         		PARAM_SINGLE_COOKIE_HEADER_VALUE); |             PARAM_SINGLE_COOKIE_HEADER_VALUE | ||||||
|  |         ); | ||||||
| 
 | 
 | ||||||
|         applyProxySettings(); |         applyProxySettings(); | ||||||
| 
 | 
 | ||||||
| @ -113,7 +115,7 @@ public class OwnCloudClient extends HttpClient { | |||||||
|                 proxyPort = Integer.parseInt(proxyPortSt); |                 proxyPort = Integer.parseInt(proxyPortSt); | ||||||
|             } |             } | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|     		// nothing to do here |             Log_OC.w(TAG, "Proxy port could not be read, keeping default value " + proxyPort); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (proxyHost != null && proxyHost.length() > 0) { |         if (proxyHost != null && proxyHost.length() > 0) { | ||||||
| @ -143,10 +145,9 @@ public class OwnCloudClient extends HttpClient { | |||||||
|     /** |     /** | ||||||
|      * Check if a file exists in the OC server |      * Check if a file exists in the OC server | ||||||
|      * |      * | ||||||
|      * @deprecated	Use ExistenceCheckOperation instead |  | ||||||
|      *  |  | ||||||
|      * @return 'true' if the file exists; 'false' it doesn't exist |      * @return 'true' if the file exists; 'false' it doesn't exist | ||||||
|      * @throws Exception When the existence could not be determined |      * @throws Exception When the existence could not be determined | ||||||
|  |      * @deprecated Use ExistenceCheckOperation instead | ||||||
|      */ |      */ | ||||||
|     @Deprecated |     @Deprecated | ||||||
|     public boolean existsFile(String path) throws IOException, HttpException { |     public boolean existsFile(String path) throws IOException, HttpException { | ||||||
| @ -206,12 +207,13 @@ public class OwnCloudClient extends HttpClient { | |||||||
|      */ |      */ | ||||||
|     @Override |     @Override | ||||||
|     public int executeMethod(HttpMethod method) throws IOException { |     public int executeMethod(HttpMethod method) throws IOException { | ||||||
|         try { |  | ||||||
|         // Update User Agent |         // Update User Agent | ||||||
|         HttpParams params = method.getParams(); |         HttpParams params = method.getParams(); | ||||||
|         String userAgent = OwnCloudClientManagerFactory.getUserAgent(); |         String userAgent = OwnCloudClientManagerFactory.getUserAgent(); | ||||||
|         params.setParameter(HttpMethodParams.USER_AGENT, userAgent); |         params.setParameter(HttpMethodParams.USER_AGENT, userAgent); | ||||||
| 
 | 
 | ||||||
|  |         preventCrashDueToInvalidPort(method); | ||||||
|  | 
 | ||||||
|         Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " + |         Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " + | ||||||
|             method.getName() + " " + method.getPath()); |             method.getName() + " " + method.getPath()); | ||||||
| 
 | 
 | ||||||
| @ -230,10 +232,32 @@ public class OwnCloudClient extends HttpClient { | |||||||
|         //logSetCookiesAtResponse(method.getResponseHeaders()); |         //logSetCookiesAtResponse(method.getResponseHeaders()); | ||||||
| 
 | 
 | ||||||
|         return status; |         return status; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         } catch (IOException e) { | 
 | ||||||
|             //Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occurred", e); |     /** | ||||||
|             throw e; |      * Fix for https://github.com/owncloud/android/issues/1847#issuecomment-267558274 | ||||||
|  |      * | ||||||
|  |      * The problem: default SocketFactory in HTTPClient 3.x for HTTP connections creates a separate thread | ||||||
|  |      * to create the socket. When a port out of TCP bounds is passed, an exception is thrown in that | ||||||
|  |      * separate thread, and our original thread is not able to catch it. This is not happenning with HTTPS | ||||||
|  |      * connections because we had to define our own socket factory, | ||||||
|  |      * {@link com.owncloud.android.lib.common.network.AdvancedSslSocketFactory}, and it does not mess with | ||||||
|  |      * threads. | ||||||
|  |      * | ||||||
|  |      * The solution: validate the input (the port number) ourselves before let the work to HTTPClient 3.x. | ||||||
|  |      * | ||||||
|  |      * @param method HTTP method to run. | ||||||
|  |      * @throws IllegalArgumentException If 'method' targets an invalid port in an HTTP URI. | ||||||
|  |      * @throws URIException             If the URI to the target server cannot be built. | ||||||
|  |      */ | ||||||
|  |     private void preventCrashDueToInvalidPort(HttpMethod method) throws URIException { | ||||||
|  |         int port = method.getURI().getPort(); | ||||||
|  |         String scheme = method.getURI().getScheme().toLowerCase(); | ||||||
|  |         if ("http".equals(scheme) && port > 0xFFFF) { | ||||||
|  |             // < 0 is not tested because -1 is used when no port number is specified in the URL; | ||||||
|  |             // no problem, the network library will convert that in the default HTTP port | ||||||
|  |             throw new IllegalArgumentException("Invalid port number " + port); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -407,7 +431,6 @@ public class OwnCloudClient extends HttpClient { | |||||||
|         if (counter == 0) { |         if (counter == 0) { | ||||||
|             Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie"); |             Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie"); | ||||||
|         } |         } | ||||||
|          |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String getCookiesString() { |     public String getCookiesString() { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user