From 7b1dd45bf94e1dafeb1df2d5a223913c21fe427e Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:14:37 +0100 Subject: [PATCH] Add support for setting up a proxy for reqwest. --- build.gradle | 2 +- config.properties | 4 ++-- src/main/java/me/kavin/piped/Main.java | 3 +++ src/main/java/me/kavin/piped/consts/Constants.java | 11 ++--------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 2e22643..b20e990 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp' implementation 'com.squareup.okhttp3:okhttp-brotli' implementation 'io.sentry:sentry:6.25.0' - implementation 'rocks.kavin:reqwest4j:1.0.5' + implementation 'rocks.kavin:reqwest4j:1.0.6' implementation 'io.minio:minio:8.5.4' } diff --git a/config.properties b/config.properties index 5b147b8..56ec594 100644 --- a/config.properties +++ b/config.properties @@ -6,8 +6,8 @@ HTTP_WORKERS:2 # Proxy PROXY_PART:https://pipedproxy-cdg.kavin.rocks -# Outgoing HTTP Proxy - eg: 127.0.0.1:8118 -#HTTP_PROXY: 127.0.0.1:8118 +# Outgoing proxy to be used by reqwest4j - eg: socks5://127.0.0.1:1080 +#REQWEST_PROXY: socks5://127.0.0.1:1080 # Captcha Parameters CAPTCHA_BASE_URL:https://api.capmonster.cloud/ diff --git a/src/main/java/me/kavin/piped/Main.java b/src/main/java/me/kavin/piped/Main.java index b38464a..a8647c0 100644 --- a/src/main/java/me/kavin/piped/Main.java +++ b/src/main/java/me/kavin/piped/Main.java @@ -20,6 +20,7 @@ import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.services.youtube.YoutubeThrottlingDecrypter; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; +import rocks.kavin.reqwest4j.ReqwestUtils; import java.util.*; import java.util.concurrent.TimeUnit; @@ -35,6 +36,8 @@ public class Main { YoutubeStreamExtractor.forceFetchAndroidClient(true); YoutubeStreamExtractor.forceFetchIosClient(true); + ReqwestUtils.init(Constants.REQWEST_PROXY); + Sentry.init(options -> { options.setDsn(Constants.SENTRY_DSN); options.setRelease(Constants.VERSION); diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index 4f338c0..b98298a 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -49,7 +49,7 @@ public class Constants { public static final String PUBSUB_HUB_URL; - public static final String HTTP_PROXY; + public static final String REQWEST_PROXY; public static final String FRONTEND_URL; @@ -129,7 +129,7 @@ public class Constants { PUBLIC_URL = getProperty(prop, "API_URL"); PUBSUB_URL = getProperty(prop, "PUBSUB_URL", PUBLIC_URL); PUBSUB_HUB_URL = getProperty(prop, "PUBSUB_HUB_URL", "https://pubsubhubbub.appspot.com/subscribe"); - HTTP_PROXY = getProperty(prop, "HTTP_PROXY"); + REQWEST_PROXY = getProperty(prop, "REQWEST_PROXY"); FRONTEND_URL = getProperty(prop, "FRONTEND_URL", "https://piped.video"); COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(getProperty(prop, "COMPROMISED_PASSWORD_CHECK", "true")); DISABLE_REGISTRATION = Boolean.parseBoolean(getProperty(prop, "DISABLE_REGISTRATION", "false")); @@ -188,13 +188,6 @@ public class Constants { OkHttpClient.Builder builder_noredir = new OkHttpClient.Builder() .followRedirects(false) .addInterceptor(BrotliInterceptor.INSTANCE); - if (HTTP_PROXY != null && HTTP_PROXY.contains(":")) { - String host = StringUtils.substringBefore(HTTP_PROXY, ":"); - String port = StringUtils.substringAfter(HTTP_PROXY, ":"); - InetSocketAddress sa = new InetSocketAddress(host, Integer.parseInt(port)); - ProxySelector ps = ProxySelector.of(sa); - ProxySelector.setDefault(ps); - } h2client = builder.build(); h2_no_redir_client = builder_noredir.build(); String temp = null;