mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Fix bug: User agent: jakarta is shown when doing GET request
This commit is contained in:
parent
43f6fe93e6
commit
94ac3a93d3
@ -41,6 +41,7 @@ import org.apache.commons.httpclient.URI;
|
|||||||
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;
|
||||||
|
import org.apache.commons.httpclient.params.HttpParams;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.params.CoreProtocolPNames;
|
import org.apache.http.params.CoreProtocolPNames;
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
private int mInstanceNumber = 0;
|
private int mInstanceNumber = 0;
|
||||||
|
|
||||||
private Uri mBaseUri;
|
private Uri mBaseUri;
|
||||||
|
private String mUserAgent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -80,8 +82,9 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
|
|
||||||
mInstanceNumber = sIntanceCounter++;
|
mInstanceNumber = sIntanceCounter++;
|
||||||
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
|
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
|
||||||
|
|
||||||
getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
|
mUserAgent = userAgent;
|
||||||
|
getParams().setParameter(HttpMethodParams.USER_AGENT, mUserAgent);
|
||||||
getParams().setParameter(
|
getParams().setParameter(
|
||||||
CoreProtocolPNames.PROTOCOL_VERSION,
|
CoreProtocolPNames.PROTOCOL_VERSION,
|
||||||
HttpVersion.HTTP_1_1);
|
HttpVersion.HTTP_1_1);
|
||||||
@ -167,9 +170,9 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
* The timeouts are both in milliseconds; 0 means 'infinite';
|
* The timeouts are both in milliseconds; 0 means 'infinite';
|
||||||
* < 0 means 'do not change the default'
|
* < 0 means 'do not change the default'
|
||||||
*
|
*
|
||||||
* @param method HTTP method request.
|
* @param method HTTP method request.
|
||||||
* @param readTimeout Timeout to set for data reception
|
* @param readTimeout Timeout to set for data reception
|
||||||
* @param conntionTimout Timeout to set for connection establishment
|
* @param connectionTimeout Timeout to set for connection establishment
|
||||||
*/
|
*/
|
||||||
public int executeMethod(HttpMethodBase method, int readTimeout, int connectionTimeout)
|
public int executeMethod(HttpMethodBase method, int readTimeout, int connectionTimeout)
|
||||||
throws HttpException, IOException {
|
throws HttpException, IOException {
|
||||||
@ -206,7 +209,11 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
*/
|
*/
|
||||||
customRedirectionNeeded = mFollowRedirects;
|
customRedirectionNeeded = mFollowRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update User Agent
|
||||||
|
HttpParams params = method.getParams();
|
||||||
|
params.setParameter(HttpMethodParams.USER_AGENT, mUserAgent);
|
||||||
|
|
||||||
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
Log_OC.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
||||||
method.getName() + " " + method.getPath());
|
method.getName() + " " + method.getPath());
|
||||||
|
|
||||||
@ -226,7 +233,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occured", e);
|
Log_OC.d(TAG + " #" + mInstanceNumber, "Exception occurred", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
import org.apache.commons.httpclient.params.HttpMethodParams;
|
||||||
|
import org.apache.commons.httpclient.params.HttpParams;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -76,7 +78,11 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
try {
|
try {
|
||||||
get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
|
get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
|
||||||
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
|
get.addRequestHeader(USER_AGENT_HEADER, getUserAgent());
|
||||||
|
|
||||||
|
HttpParams params = get.getParams().getDefaultParams();
|
||||||
|
params.setParameter(HttpMethodParams.USER_AGENT, getUserAgent());
|
||||||
|
get.getParams().setDefaults(params);
|
||||||
|
|
||||||
client.setFollowRedirects(false);
|
client.setFollowRedirects(false);
|
||||||
boolean isRedirectToNonSecureConnection = false;
|
boolean isRedirectToNonSecureConnection = false;
|
||||||
int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
|
int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user