aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2018-12-19 11:09:13 +0000
committerLuck <git@lucko.me>2018-12-19 11:09:13 +0000
commit15db7c3fec20034bebe243bef52a0129112cbae1 (patch)
treeb9dd1aabefba2b19ff638fcc497042b68f0f0ebd /spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java
parent320d6a28b60873c8e8163b27ed1389978aed4ee6 (diff)
downloadspark-15db7c3fec20034bebe243bef52a0129112cbae1.tar.gz
spark-15db7c3fec20034bebe243bef52a0129112cbae1.tar.bz2
spark-15db7c3fec20034bebe243bef52a0129112cbae1.zip
Update okhttp version
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java54
1 files changed, 1 insertions, 53 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java b/spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java
index 01f63f7..00e1c69 100644
--- a/spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java
+++ b/spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java
@@ -31,12 +31,6 @@ import okhttp3.RequestBody;
import okhttp3.Response;
import java.io.IOException;
-import java.net.Proxy;
-import java.net.ProxySelector;
-import java.net.SocketAddress;
-import java.net.URI;
-import java.util.Collections;
-import java.util.List;
/**
* Utility for posting content to bytebin.
@@ -63,31 +57,7 @@ public class BytebinClient {
this.url = url + "/post";
}
this.userAgent = userAgent;
- this.okHttp = new OkHttpClient.Builder()
- .proxySelector(new NullSafeProxySelector())
- .build();
- }
-
- /**
- * Posts content to bytebin.
- *
- * @param buf the content
- * @param contentType the type of the content
- * @return the key of the resultant content
- * @throws IOException if an error occurs
- */
- public String postContent(byte[] buf, MediaType contentType) throws IOException {
- RequestBody body = RequestBody.create(contentType, buf);
-
- Request.Builder requestBuilder = new Request.Builder()
- .header("User-Agent", this.userAgent)
- .url(this.url)
- .post(body);
-
- Request request = requestBuilder.build();
- try (Response response = makeHttpRequest(request)) {
- return response.header("Location");
- }
+ this.okHttp = new OkHttpClient();
}
/**
@@ -120,26 +90,4 @@ public class BytebinClient {
}
return response;
}
-
- // sometimes ProxySelector#getDefault returns null, and okhttp doesn't like that
- private static final class NullSafeProxySelector extends ProxySelector {
- private static final List<Proxy> DIRECT = Collections.singletonList(Proxy.NO_PROXY);
-
- @Override
- public List<Proxy> select(URI uri) {
- ProxySelector def = ProxySelector.getDefault();
- if (def == null) {
- return DIRECT;
- }
- return def.select(uri);
- }
-
- @Override
- public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
- ProxySelector def = ProxySelector.getDefault();
- if (def != null) {
- def.connectFailed(uri, sa, ioe);
- }
- }
- }
}