From e5c03079b6e5e1f73bfccaf02fbdeba4560b7e89 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sun, 12 Apr 2015 01:40:09 +0200 Subject: [PATCH] Another fix... --- core/build.gradle | 6 +-- .../core/asynctask/PicassoProvider.java | 45 ++++++++++--------- .../core/gpoddernet/GpodnetService.java | 7 ++- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index c327f194c..61978e898 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -40,9 +40,9 @@ dependencies { compile 'commons-io:commons-io:2.4' compile 'com.jayway.android.robotium:robotium-solo:5.2.1' compile 'org.jsoup:jsoup:1.7.3' - compile 'com.squareup.picasso:picasso:2.4.0' - compile 'com.squareup.okhttp:okhttp:2.2.0' - compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' + compile 'com.squareup.picasso:picasso:2.5.2' + compile 'com.squareup.okhttp:okhttp:2.3.0' + compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0' compile 'com.squareup.okio:okio:1.2.0' compile 'com.nineoldandroids:library:2.4.0' compile 'de.greenrobot:eventbus:2.4.0' diff --git a/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java b/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java index e91ae3322..0b637c682 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java +++ b/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java @@ -66,7 +66,7 @@ public class PicassoProvider { return; } OkHttpClient client = new OkHttpClient(); - client.networkInterceptors().add(new BasicAuthenticationInterceptor(appContext)); + client.interceptors().add(new BasicAuthenticationInterceptor(appContext)); Picasso picasso = new Picasso.Builder(appContext) .indicatorsEnabled(DEBUG) .loggingEnabled(DEBUG) @@ -98,29 +98,32 @@ public class PicassoProvider { public Response intercept(Chain chain) throws IOException { com.squareup.okhttp.Request request = chain.request(); String url = request.urlString(); - // add authentication String authentication = DBReader.getImageAuthentication(context, url); - if(TextUtils.isEmpty(authentication) == false) { - String[] auth = authentication.split(":"); - String credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "ISO-8859-1"); - com.squareup.okhttp.Request newRequest = request + + if(TextUtils.isEmpty(authentication)) { + Log.d(TAG, "no credentials for '" + url + "'"); + return chain.proceed(request); + } + + // add authentication + String[] auth = authentication.split(":"); + String credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "ISO-8859-1"); + com.squareup.okhttp.Request newRequest = request + .newBuilder() + .addHeader("Authorization", credentials) + .build(); + Log.d(TAG, "Basic authentication with ISO-8859-1 encoding"); + Response response = chain.proceed(newRequest); + if (!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { + credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "UTF-8"); + newRequest = request .newBuilder() .addHeader("Authorization", credentials) .build(); - Response response = chain.proceed(newRequest); - if (!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { - credentials = HttpDownloader.encodeCredentials(auth[0], auth[1], "UTF-8"); - newRequest = request - .newBuilder() - .addHeader("Authorization", credentials) - .build(); - return chain.proceed(newRequest); - } else { - return response; - } - } - else { // no authentication required - return chain.proceed(request); + Log.d(TAG, "Basic authentication with UTF-8 encoding"); + return chain.proceed(newRequest); + } else { + return response; } } } @@ -140,7 +143,7 @@ public class PicassoProvider { } @Override - public Result load(Request data) throws IOException { + public Result load(Request data, int networkPolicy) throws IOException { Bitmap bitmap = null; MediaMetadataRetriever mmr = null; try { diff --git a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java index db242c3bc..23d89a3a3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java @@ -726,7 +726,12 @@ public class GpodnetService { Validate.notNull(body); ByteArrayOutputStream outputStream; - int contentLength = (int) body.contentLength(); + int contentLength = 0; + try { + contentLength = (int) body.contentLength(); + } catch (IOException ignore) { + // ignore + } if (contentLength > 0) { outputStream = new ByteArrayOutputStream(contentLength); } else {