Skip to content

Commit

Permalink
Merge pull request #4549 from hieupham007/timob-14224
Browse files Browse the repository at this point in the history
timob-14224: Add system-wide cookie store for httpclient
  • Loading branch information
pingwang2011 committed Aug 23, 2013
2 parents 11f4feb + 5f66f7e commit c9a03d8
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.http.auth.Credentials;
import org.apache.http.auth.NTCredentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
Expand All @@ -74,6 +75,7 @@
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.DefaultHttpRequestFactory;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultRedirectHandler;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
Expand Down Expand Up @@ -101,11 +103,11 @@
import org.appcelerator.titanium.util.TiMimeTypeHelper;
import org.appcelerator.titanium.util.TiPlatformHelper;
import org.appcelerator.titanium.util.TiUrl;
import android.os.Build;

import ti.modules.titanium.xml.DocumentProxy;
import ti.modules.titanium.xml.XMLModule;
import android.net.Uri;
import android.os.Build;

public class TiHTTPClient
{
Expand Down Expand Up @@ -162,6 +164,9 @@ public class TiHTTPClient
private ArrayList<X509TrustManager> trustManagers = new ArrayList<X509TrustManager>();
private ArrayList<X509KeyManager> keyManagers = new ArrayList<X509KeyManager>();

private static CookieStore cookieStore = new BasicCookieStore();


protected HashMap<String,String> headers = new HashMap<String,String>();

private Hashtable<String, AuthSchemeFactory> customAuthenticators = new Hashtable<String, AuthSchemeFactory>(1);
Expand Down Expand Up @@ -692,7 +697,6 @@ public void abort()
{
if (readyState > READY_STATE_UNSENT && readyState < READY_STATE_DONE) {
aborted = true;

if (client != null) {
client.getConnectionManager().shutdown();
client = null;
Expand All @@ -701,6 +705,7 @@ public void abort()
validatingClient = null;
if (nonValidatingClient != null)
nonValidatingClient = null;

}
}

Expand Down Expand Up @@ -1011,8 +1016,11 @@ protected DefaultHttpClient createClient()

HttpProtocolParams.setUseExpectContinue(params, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

DefaultHttpClient httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, registry), params);
httpClient.setCookieStore(cookieStore);

return new DefaultHttpClient(new ThreadSafeClientConnManager(params, registry), params);
return httpClient;
}

protected DefaultHttpClient getClient(boolean validating)
Expand Down Expand Up @@ -1269,7 +1277,6 @@ public void progress(int progress) {
String result = null;
try {
result = client.execute(host, request, handler);

} catch (IOException e) {
if (!aborted) {
throw e;
Expand Down

0 comments on commit c9a03d8

Please sign in to comment.