diff options
author | Luck <git@lucko.me> | 2018-12-19 11:09:13 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2018-12-19 11:09:13 +0000 |
commit | 15db7c3fec20034bebe243bef52a0129112cbae1 (patch) | |
tree | b9dd1aabefba2b19ff638fcc497042b68f0f0ebd /spark-common | |
parent | 320d6a28b60873c8e8163b27ed1389978aed4ee6 (diff) | |
download | spark-15db7c3fec20034bebe243bef52a0129112cbae1.tar.gz spark-15db7c3fec20034bebe243bef52a0129112cbae1.tar.bz2 spark-15db7c3fec20034bebe243bef52a0129112cbae1.zip |
Update okhttp version
Diffstat (limited to 'spark-common')
-rw-r--r-- | spark-common/build.gradle | 3 | ||||
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/util/BytebinClient.java | 54 |
2 files changed, 3 insertions, 54 deletions
diff --git a/spark-common/build.gradle b/spark-common/build.gradle index 453bbdd..60dbf0c 100644 --- a/spark-common/build.gradle +++ b/spark-common/build.gradle @@ -1,5 +1,6 @@ dependencies { - compile 'com.squareup.okhttp3:okhttp:3.10.0' + compile 'com.squareup.okhttp3:okhttp:3.12.0' + compile 'com.squareup.okio:okio:1.16.0' compileOnly 'com.google.code.gson:gson:2.7' compileOnly 'com.google.guava:guava:19.0' } 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); - } - } - } } |