import java.io.IOException;
import java.util.concurrent.TimeUnit;
-
import net.pterodactylus.rhynodge.Query;
import net.pterodactylus.rhynodge.State;
import net.pterodactylus.rhynodge.states.FailedState;
import net.pterodactylus.rhynodge.states.HttpState;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.protocol.ResponseContentEncoding;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.util.EntityUtils;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.config.ConnectionConfig;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
+import org.apache.hc.client5.http.ssl.HostnameVerificationPolicy;
+import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.protocol.ResponseContent;
+import org.apache.hc.core5.ssl.SSLContexts;
import org.jspecify.annotations.Nullable;
/**
@Override
@SuppressWarnings("deprecation")
public State state() {
- HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
- .setSSLHostnameVerifier((hostname, session) -> true)
- .addInterceptorFirst(new ResponseContentEncoding());
+ var acceptAllHostnamesStrategy = new DefaultClientTlsStrategy(SSLContexts.createDefault(), HostnameVerificationPolicy.CLIENT, NoopHostnameVerifier.INSTANCE);
+ var connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
+ .setTlsSocketStrategy(acceptAllHostnamesStrategy)
+ .setDefaultConnectionConfig(ConnectionConfig.custom()
+ .setConnectTimeout(300, TimeUnit.SECONDS)
+ .setSocketTimeout(300, TimeUnit.SECONDS).build())
+ .build();
+ var httpClientBuilder = HttpClients.custom()
+ .setConnectionManager(connectionManager)
+ .addResponseInterceptorFirst(new ResponseContent());
if ((proxyHost != null) && (proxyPort != -1)) {
httpClientBuilder.setProxy(new HttpHost(proxyHost, proxyPort));
}
- HttpClient httpClient = httpClientBuilder.build();
- HttpGet get = new HttpGet(uri);
+ var get = new HttpGet(uri);
- try {
+ try (var httpClient = httpClientBuilder.build()) {
/* make request. */
get.addHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11");
- HttpConnectionParams.setConnectionTimeout(get.getParams(), (int) TimeUnit.SECONDS.toMillis(300));
- HttpConnectionParams.setSoTimeout(get.getParams(), (int) TimeUnit.SECONDS.toMillis(300));
- HttpResponse response = httpClient.execute(get);
- if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- return new FailedState(new IllegalStateException(String.format("Invalid HTTP Status: %d", response.getStatusLine().getStatusCode())));
+ var response = httpClient.execute(get);
+ if (response.getCode() != HttpStatus.SC_OK) {
+ return new FailedState(new IllegalStateException(String.format("Invalid HTTP Status: %d", response.getCode())));
}
- HttpEntity entity = response.getEntity();
+ var entity = response.getEntity();
/* yay, done! */
- return new HttpState(uri, response.getStatusLine().getStatusCode(), entity.getContentType().getValue(), EntityUtils.toByteArray(entity));
-
+ return new HttpState(uri, response.getCode(), entity.getContentType(), EntityUtils.toByteArray(entity));
} catch (IOException ioe1) {
return new FailedState(ioe1);
}
import net.pterodactylus.rhynodge.State;
import net.pterodactylus.rhynodge.queries.HttpQuery;
-import org.apache.http.HeaderElement;
-import org.apache.http.NameValuePair;
-import org.apache.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.NameValuePair;
+import org.apache.hc.core5.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.message.ParserCursor;
/**
* {@link State} that contains the results of an {@link HttpQuery}.
if (contentType == null) {
return "ISO-8859-1";
}
- HeaderElement headerElement = BasicHeaderValueParser.parseHeaderElement(contentType, new BasicHeaderValueParser());
+ HeaderElement headerElement = BasicHeaderValueParser.INSTANCE.parseHeaderElement(contentType, new ParserCursor(0, contentType.length()));
NameValuePair charset = headerElement.getParameterByName("charset");
return (charset != null) ? charset.getValue() : "ISO-8859-1";
}
package net.pterodactylus.rhynodge.states;
-import java.nio.charset.StandardCharsets;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.hc.core5.http.NameValuePair;
+import org.apache.hc.core5.net.WWWFormCodec;
import static java.lang.String.format;
+import static java.nio.charset.StandardCharsets.UTF_8;
/**
* {@link State} that contains information about an arbitrary number of torrent
if ((magnetUri == null) || (magnetUri.length() < 8)) {
return Optional.empty();
}
- List<NameValuePair> parameters = URLEncodedUtils.parse(magnetUri.substring("magnet:?".length()), StandardCharsets.UTF_8);
+ List<NameValuePair> parameters = WWWFormCodec.parse(URI.create(magnetUri).getSchemeSpecificPart(), UTF_8);
for (NameValuePair parameter : parameters) {
if (parameter.getName().equals("xt")) {
return Optional.of(parameter.getValue().toLowerCase());