Tweak 403 handling

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 3 years ago
parent b6ce2a62f0
commit 8b3d26a4d4

@ -180,7 +180,7 @@ public class Http {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
public static void captchaWebview(String url) { public static void captchaWebview(String url) {
if (hasWebView) { if (hasWebView) {
// Open the specified url in a webview // Open the specified url in a webview
WebView webView = new WebView(mainApplication); WebView webView = new WebView(mainApplication);
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUserAgentString(androidacyUA); webView.getSettings().setUserAgentString(androidacyUA);
@ -203,13 +203,11 @@ public class Http {
} }
Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(new Request.Builder().url(url).get().build()).execute(); Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(new Request.Builder().url(url).get().build()).execute();
// 200/204 == success, 304 == cache valid // 200/204 == success, 304 == cache valid
if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) { if (response.code() == 403 && AndroidacyUtil.isAndroidacyLink(url)) {
// If error is 403 and it's an Androidacy link, it's probably a 403 from Cloudflare // Open webview to solve captcha
// and we should open a webview to solve the captcha Log.e(TAG, "Received 403 error code, opening webview to solve captcha");
if (response.code() == 403 && AndroidacyUtil.isAndroidacyLink(url)) { captchaWebview(url);
// Open webview to solve captcha } else if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) {
captchaWebview(url);
}
throw new IOException("Received error code: " + response.code()); throw new IOException("Received error code: " + response.code());
} }
ResponseBody responseBody = response.body(); ResponseBody responseBody = response.body();
@ -243,8 +241,6 @@ public class Http {
// Open webview to solve captcha // Open webview to solve captcha
Log.e(TAG, "Received 403 error code, opening webview to solve captcha"); Log.e(TAG, "Received 403 error code, opening webview to solve captcha");
captchaWebview(url); captchaWebview(url);
} else if (isRedirect) {
return url;
} else if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) { } else if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) {
throw new IOException("Received error code: " + response.code()); throw new IOException("Received error code: " + response.code());
} }

Loading…
Cancel
Save