Add support for setting up a proxy for reqwest.

This commit is contained in:
Kavin 2023-07-04 19:14:37 +01:00
parent ab3bf4ec98
commit 7b1dd45bf9
No known key found for this signature in database
GPG Key ID: 6E4598CA5C92C41F
4 changed files with 8 additions and 12 deletions

View File

@ -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'
}

View File

@ -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/

View File

@ -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);

View File

@ -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;