Browse Source

Merge branch 'bugfix/105-transmission-preemptive' into dev

pull/424/head
Eric Kok 7 years ago
parent
commit
d9f64e3d2d
  1. 19
      app/src/main/java/org/transdroid/daemon/Transmission/TransmissionAdapter.java

19
app/src/main/java/org/transdroid/daemon/Transmission/TransmissionAdapter.java

@ -17,6 +17,8 @@ @@ -17,6 +17,8 @@
*/
package org.transdroid.daemon.Transmission;
import android.text.TextUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@ -416,6 +418,13 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -416,6 +418,13 @@ public class TransmissionAdapter implements IDaemonAdapter {
httppost.addHeader(sessionHeader, sessionToken);
}
// Force preemptive authentication. This makes sure there is an 'Authentication: ' header being send before trying and failing and
// retrying by the basic authentication mechanism of DefaultHttpClient
if (settings.shouldUseAuthentication() && !TextUtils.isEmpty(settings.getUsername())) {
httppost.addHeader("Authorization", "Basic " +
Base64.encodeBytes((settings.getUsername() + ":" + settings.getPassword()).getBytes()));
}
// Execute
log.d(LOG_NAME, "Execute " + data.getString("method") + " request to " + httppost.getURI().toString());
HttpResponse response = httpclient.execute(httppost);
@ -447,7 +456,7 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -447,7 +456,7 @@ public class TransmissionAdapter implements IDaemonAdapter {
java.io.InputStream instream = entity.getContent();
String result = HttpHelper.convertStreamToString(instream);
log.d(LOG_NAME, "Received content response starting with " +
(result.length() > 100 ? result.substring(0, 100) + "..." : result));
(result.length() > 100 ? result.substring(0, 100) + "..." : result));
JSONObject json = new JSONObject(result);
instream.close();
@ -499,7 +508,7 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -499,7 +508,7 @@ public class TransmissionAdapter implements IDaemonAdapter {
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONObject response) throws JSONException {
// Parse response
ArrayList<Torrent> torrents = new ArrayList<Torrent>();
ArrayList<Torrent> torrents = new ArrayList<>();
JSONArray rarray = response.getJSONArray("torrents");
for (int i = 0; i < rarray.length(); i++) {
JSONObject tor = rarray.getJSONObject(i);
@ -580,7 +589,7 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -580,7 +589,7 @@ public class TransmissionAdapter implements IDaemonAdapter {
private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, Torrent torrent) throws JSONException {
// Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>();
ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
JSONArray rarray = response.getJSONArray("torrents");
if (rarray.length() > 0) {
JSONArray files = rarray.getJSONObject(0).getJSONArray("files");
@ -628,12 +637,12 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -628,12 +637,12 @@ public class TransmissionAdapter implements IDaemonAdapter {
JSONArray rarray = response.getJSONArray("torrents");
if (rarray.length() > 0) {
JSONArray trackersList = rarray.getJSONObject(0).getJSONArray("trackers");
List<String> trackers = new ArrayList<String>();
List<String> trackers = new ArrayList<>();
for (int i = 0; i < trackersList.length(); i++) {
trackers.add(trackersList.getJSONObject(i).getString("announce"));
}
JSONArray trackerStatsList = rarray.getJSONObject(0).getJSONArray("trackerStats");
List<String> errors = new ArrayList<String>();
List<String> errors = new ArrayList<>();
for (int i = 0; i < trackerStatsList.length(); i++) {
// Get the tracker response and if it was an error then add it
String lar = trackerStatsList.getJSONObject(i).getString("lastAnnounceResult");

Loading…
Cancel
Save