清理 HttpRequest (#6666)
This commit is contained in:
1 file changed
+12
-17
@@ -21,7 +21,6 @@ import com.google.gson.JsonParseException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.util.Pair;
|
||||
import org.jackhuang.hmcl.util.function.ExceptionalBiConsumer;
|
||||
import org.jackhuang.hmcl.util.function.ExceptionalSupplier;
|
||||
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||
|
||||
@@ -29,7 +28,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -47,7 +45,6 @@ public abstract class HttpRequest {
|
||||
protected final String url;
|
||||
protected final String method;
|
||||
protected final Map<String, String> headers = new HashMap<>();
|
||||
protected ExceptionalBiConsumer<URL, Integer, IOException> responseCodeTester;
|
||||
protected final Set<Integer> toleratedHttpCodes = new HashSet<>();
|
||||
protected int retryTimes = 1;
|
||||
protected boolean ignoreHttpCode;
|
||||
@@ -73,10 +70,6 @@ public abstract class HttpRequest {
|
||||
return authorization(tokenType + " " + tokenString);
|
||||
}
|
||||
|
||||
public HttpRequest authorization(Authorization authorization) {
|
||||
return authorization(authorization.getTokenType(), authorization.getAccessToken());
|
||||
}
|
||||
|
||||
public HttpRequest header(String key, String value) {
|
||||
headers.put(key, value);
|
||||
return this;
|
||||
@@ -164,11 +157,15 @@ public abstract class HttpRequest {
|
||||
}
|
||||
|
||||
public static class HttpGetRequest extends HttpSimpleRequest {
|
||||
protected HttpGetRequest(String url) { super(url, "GET"); }
|
||||
protected HttpGetRequest(String url) {
|
||||
super(url, "GET");
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpDeleteRequest extends HttpSimpleRequest {
|
||||
protected HttpDeleteRequest(String url) { super(url, "DELETE"); }
|
||||
protected HttpDeleteRequest(String url) {
|
||||
super(url, "DELETE");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -223,11 +220,15 @@ public abstract class HttpRequest {
|
||||
}
|
||||
|
||||
public static final class HttpPostRequest extends HttpEntityRequest<HttpPostRequest> {
|
||||
private HttpPostRequest(String url) { super(url, "POST"); }
|
||||
private HttpPostRequest(String url) {
|
||||
super(url, "POST");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class HttpPutRequest extends HttpEntityRequest<HttpPutRequest> {
|
||||
private HttpPutRequest(String url) { super(url, "PUT"); }
|
||||
private HttpPutRequest(String url) {
|
||||
super(url, "PUT");
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpGetRequest GET(String url) {
|
||||
@@ -274,10 +275,4 @@ public abstract class HttpRequest {
|
||||
}
|
||||
throw new IOException("retry 0");
|
||||
}
|
||||
|
||||
public interface Authorization {
|
||||
String getTokenType();
|
||||
|
||||
String getAccessToken();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user