mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Simplify logic and fix typos.
This commit is contained in:
parent
3a6df12844
commit
46e449a5df
2 changed files with 15 additions and 17 deletions
|
@ -7,8 +7,8 @@ HTTP_WORKERS: 2
|
||||||
# Proxy
|
# Proxy
|
||||||
PROXY_PART: https://pipedproxy-ams.kavin.rocks
|
PROXY_PART: https://pipedproxy-ams.kavin.rocks
|
||||||
|
|
||||||
# Ougoing HTTP proxy host:port (for both https and http requests)
|
# Outgoing HTTP Proxy - eg: 127.0.0.1:8118
|
||||||
HTTP_PROXY:
|
#HTTP_PROXY: 127.0.0.1:8118
|
||||||
|
|
||||||
# Captcha Parameters
|
# Captcha Parameters
|
||||||
CAPTCHA_BASE_URL: https://api.capmonster.cloud/
|
CAPTCHA_BASE_URL: https://api.capmonster.cloud/
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package me.kavin.piped.consts;
|
package me.kavin.piped.consts;
|
||||||
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ProxySelector;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpClient.Builder;
|
import java.net.http.HttpClient.Builder;
|
||||||
import java.net.http.HttpClient.Redirect;
|
import java.net.http.HttpClient.Redirect;
|
||||||
import java.net.http.HttpClient.Version;
|
import java.net.http.HttpClient.Version;
|
||||||
import java.net.ProxySelector;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.Page;
|
import org.schabi.newpipe.extractor.Page;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
@ -40,7 +40,6 @@ public class Constants {
|
||||||
|
|
||||||
public static final HttpClient h2client;
|
public static final HttpClient h2client;
|
||||||
public static final HttpClient h2_no_redir_client;
|
public static final HttpClient h2_no_redir_client;
|
||||||
// public static final HttpClient h3client = Http3ClientBuilder.newBuilder().followRedirects(Redirect.NORMAL).build();
|
|
||||||
|
|
||||||
public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class);
|
public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class);
|
||||||
|
|
||||||
|
@ -64,18 +63,17 @@ public class Constants {
|
||||||
if (key.startsWith("hibernate"))
|
if (key.startsWith("hibernate"))
|
||||||
hibernateProperties.put(key, value);
|
hibernateProperties.put(key, value);
|
||||||
});
|
});
|
||||||
Builder h2c = HttpClient.newBuilder().followRedirects(Redirect.NORMAL)
|
Builder builder = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).version(Version.HTTP_2);
|
||||||
.version(Version.HTTP_2);
|
Builder builder_noredir = HttpClient.newBuilder().followRedirects(Redirect.NEVER).version(Version.HTTP_2);
|
||||||
Builder h2nrc = HttpClient.newBuilder().followRedirects(Redirect.NEVER)
|
if (HTTP_PROXY != null && HTTP_PROXY.contains(":")) {
|
||||||
.version(Version.HTTP_2);
|
String host = StringUtils.substringBefore(HTTP_PROXY, ":");
|
||||||
if (HTTP_PROXY != null && !HTTP_PROXY.trim().isEmpty()) {
|
String port = StringUtils.substringAfter(HTTP_PROXY, ":");
|
||||||
String[] parts = HTTP_PROXY.split(":");
|
InetSocketAddress sa = new InetSocketAddress(host, Integer.parseInt(port));
|
||||||
ProxySelector proxy = ProxySelector.of(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
|
ProxySelector ps = ProxySelector.of(sa);
|
||||||
h2c = h2c.proxy(proxy);
|
ProxySelector.setDefault(ps);
|
||||||
h2nrc = h2nrc.proxy(proxy);
|
|
||||||
}
|
}
|
||||||
h2client = h2c.build();
|
h2client = builder.build();
|
||||||
h2_no_redir_client = h2nrc.build();
|
h2_no_redir_client = builder_noredir.build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue