Skip to content

Commit 31e5d02

Browse files
committed
Fixing android-async-http#79, Allowing non-standard HTTP and HTTPS ports
1 parent 51dfd5a commit 31e5d02

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

library/src/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,40 @@ public class AsyncHttpClient {
118118

119119

120120
/**
121-
* Creates a new AsyncHttpClient.
121+
* Creates a new AsyncHttpClient with default constructor arguments values
122122
*/
123123
public AsyncHttpClient() {
124-
this(false);
124+
this(false, 80, 443);
125+
}
126+
127+
/**
128+
* Creates a new AsyncHttpClient.
129+
*
130+
* @param httpPort non-standard HTTP-only port
131+
*/
132+
public AsyncHttpClient(int httpPort) {
133+
this(false, httpPort, 443);
134+
}
135+
136+
/**
137+
* Creates a new AsyncHttpClient.
138+
*
139+
* @param httpPort non-standard HTTP-only port
140+
* @param httpsPort non-standard HTTPS-only port
141+
*/
142+
public AsyncHttpClient(int httpPort, int httpsPort) {
143+
this(false, httpPort, httpsPort);
125144
}
126145

127146
/**
128147
* Creates a new AsyncHttpClient.
129148
*
130149
* @param fixNoHttpResponseException See issue https://github.com/loopj/android-async-http/issues/143
150+
* @param httpPort non-standard HTTP-only port
151+
* @param httpsPort non-standard HTTPS-only port
131152
*/
132-
public AsyncHttpClient(boolean fixNoHttpResponseException) {
133-
if(fixNoHttpResponseException)
153+
public AsyncHttpClient(boolean fixNoHttpResponseException, int httpPort, int httpsPort) {
154+
if (fixNoHttpResponseException)
134155
Log.d(LOG_TAG, "Beware! Using the fix is insecure, as it doesn't verify SSL certificates.");
135156
BasicHttpParams httpParams = new BasicHttpParams();
136157

@@ -155,8 +176,8 @@ public AsyncHttpClient(boolean fixNoHttpResponseException) {
155176
sslSocketFactory = SSLSocketFactory.getSocketFactory();
156177

157178
SchemeRegistry schemeRegistry = new SchemeRegistry();
158-
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
159-
schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
179+
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), httpPort));
180+
schemeRegistry.register(new Scheme("https", sslSocketFactory, httpsPort));
160181

161182
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
162183

0 commit comments

Comments
 (0)