Skip to content

Commit

Permalink
Merge pull request #641 from TeamPiped/reqwest-proxy
Browse files Browse the repository at this point in the history
Add support for setting up a proxy for reqwest.
  • Loading branch information
FireMasterK authored Jul 4, 2023
2 parents ab3bf4e + 7b1dd45 commit 6a2c688
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
4 changes: 2 additions & 2 deletions config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/me/kavin/piped/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand All @@ -35,6 +36,8 @@ public static void main(String[] args) throws Exception {
YoutubeStreamExtractor.forceFetchAndroidClient(true);
YoutubeStreamExtractor.forceFetchIosClient(true);

ReqwestUtils.init(Constants.REQWEST_PROXY);

Sentry.init(options -> {
options.setDsn(Constants.SENTRY_DSN);
options.setRelease(Constants.VERSION);
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/me/kavin/piped/consts/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -188,13 +188,6 @@ else if (key.startsWith("frontend."))
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;
Expand Down

0 comments on commit 6a2c688

Please sign in to comment.