-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[TIMOB-24809] Android: HTTPClient - "onload" not dispatched. #9139
Changes from 5 commits
4a8587e
44e5200
34eb14d
5803b24
429dc6c
eadd4e6
e1246f6
e273431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
||
|
@@ -730,6 +731,11 @@ public String getResponseHeader(String getHeaderName) | |
|
||
public void open(String method, String url) | ||
{ | ||
if (requestPending) { | ||
Log.w(TAG,"Open canceled. Connection is already opened and a request is pending."); | ||
return; | ||
} | ||
|
||
Log.d(TAG, "open request method=" + method + " url=" + url, Log.DEBUG_MODE); | ||
|
||
if (url == null) | ||
|
@@ -1009,6 +1015,13 @@ private Object titaniumFileAsPutData(Object value) | |
|
||
public void send(Object userData) throws UnsupportedEncodingException | ||
{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to clear the values only after they have been used: if (nvPairs.size() > 0) {
try {
form = new UrlEncodedFormEntity(nvPairs, "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unsupported encoding: ", e);
}
nvPairs.clear();
} for(String name : parts.keySet()) {
Log.d(TAG, "adding part " + name + ", part type: " + parts.get(name).getMimeType() + ", len: "
+ parts.get(name).getContentLength(), Log.DEBUG_MODE);
addFilePart(name, parts.get(name));
}
parts.clear(); |
||
if (requestPending) { | ||
//Log.w(TAG,"Request currently in transmission!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this commented line |
||
Log.w(TAG,"Send canceled. A request with the same TiHTTPClient is pending!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return; | ||
} | ||
requestPending = true; | ||
aborted = false; | ||
|
||
// TODO consider using task manager | ||
|
@@ -1143,6 +1156,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 | ||
|
@@ -1196,7 +1211,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()); | ||
|
@@ -1298,7 +1314,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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.