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

Merge pull request #143 from owncloud/release_0.9.15

Release 0.9.15
This commit is contained in:
David A. Velasco 2016-12-20 16:31:25 +01:00 committed by GitHub
commit a68f7769dc

View File

@ -39,6 +39,7 @@ import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
@ -90,13 +91,14 @@ public class OwnCloudClient extends HttpClient {
getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
getParams().setParameter(
PARAM_PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
HttpVersion.HTTP_1_1
);
getParams().setCookiePolicy(
CookiePolicy.IGNORE_COOKIES);
getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
getParams().setParameter(
PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers
PARAM_SINGLE_COOKIE_HEADER_VALUE);
PARAM_SINGLE_COOKIE_HEADER_VALUE
);
applyProxySettings();
@ -113,7 +115,7 @@ public class OwnCloudClient extends HttpClient {
proxyPort = Integer.parseInt(proxyPortSt);
}
} 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) {
@ -143,10 +145,9 @@ public class OwnCloudClient extends HttpClient {
/**
* Check if a file exists in the OC server
*
* @deprecated Use ExistenceCheckOperation instead
*
* @return 'true' if the file exists; 'false' it doesn't exist
* @throws Exception When the existence could not be determined
* @deprecated Use ExistenceCheckOperation instead
*/
@Deprecated
public boolean existsFile(String path) throws IOException, HttpException {
@ -206,12 +207,13 @@ public class OwnCloudClient extends HttpClient {
*/
@Override
public int executeMethod(HttpMethod method) throws IOException {
try {
// Update User Agent
HttpParams params = method.getParams();
String userAgent = OwnCloudClientManagerFactory.getUserAgent();
params.setParameter(HttpMethodParams.USER_AGENT, userAgent);
preventCrashDueToInvalidPort(method);
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
method.getName() + " " + method.getPath());
@ -230,10 +232,32 @@ public class OwnCloudClient extends HttpClient {
//logSetCookiesAtResponse(method.getResponseHeaders());
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) {
Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie");
}
}
public String getCookiesString() {