Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6_1_X][TIMOB-24809] Android: HTTPClient - "onload" not dispatched. #9140

Merged
merged 7 commits into from
Jun 14, 2017
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

import android.util.Base64;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBlob;
Expand Down Expand Up @@ -155,6 +154,8 @@ public class TiHTTPClient
private String username;
private String password;

private boolean requestPending = false;

private void handleResponse(HttpURLConnection connection) throws IOException {
connected = true;

Expand Down Expand Up @@ -730,6 +731,11 @@ public String getResponseHeader(String getHeaderName)

public void open(String method, String url)
{
if (requestPending) {
Log.w(TAG, "open cancelled, a request is already pending for response.");
return;
}

Log.d(TAG, "open request method=" + method + " url=" + url, Log.DEBUG_MODE);

if (url == null)
Expand Down Expand Up @@ -1009,6 +1015,12 @@ private Object titaniumFileAsPutData(Object value)

public void send(Object userData) throws UnsupportedEncodingException
{

if (requestPending) {
Log.w(TAG, "send cancelled, a request is already pending for response.");
return;
}
requestPending = true;
aborted = false;

// TODO consider using task manager
Expand Down Expand Up @@ -1143,6 +1155,8 @@ public void run()
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unsupported encoding: ", e);
}
//clear nvPairs after form entity is created
nvPairs.clear();
}

// calculate content length
Expand Down Expand Up @@ -1196,7 +1210,8 @@ public void progress(int progress) {
+ parts.get(name).getContentLength(), Log.DEBUG_MODE);
addFilePart(name, parts.get(name));
}

//clear parts after they have been used
parts.clear();
if (form != null) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream((int) form.getContentLength());
Expand Down Expand Up @@ -1298,7 +1313,7 @@ public void progress(int progress) {

client = null;
clientThread = null;

requestPending = false;
// Fire the disposehandle event if the request is finished successfully or the errors occur.
// And it will dispose the handle of the httpclient in the JS.
proxy.fireEvent(TiC.EVENT_DISPOSE_HANDLE, null);
Expand Down