Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2733 protocol-okhttp: add support for Brotli compression (Content-Encoding) - add dependency to okhttp3.brotli - enable Brotli compression via Accept-Encoding

Sebastian Nagel6f1a0ddd973a
diff --git a/src/plugin/protocol-okhttp/ivy.xml b/src/plugin/protocol-okhttp/ivy.xml
index f1b625663..ee856849e 100644
--- a/src/plugin/protocol-okhttp/ivy.xml
+++ b/src/plugin/protocol-okhttp/ivy.xml
@@ -37,6 +37,7 @@
<dependencies>
<dependency org="com.squareup.okhttp3" name="okhttp" rev="4.3.1"/>
+ <dependency org="com.squareup.okhttp3" name="okhttp-brotli" rev="4.3.1"/>
</dependencies>
</ivy-module>
diff --git a/src/plugin/protocol-okhttp/plugin.xml b/src/plugin/protocol-okhttp/plugin.xml
index 2ff31e6ce..bbeb5daf5 100755
--- a/src/plugin/protocol-okhttp/plugin.xml
+++ b/src/plugin/protocol-okhttp/plugin.xml
@@ -30,6 +30,8 @@
<library name="kotlin-stdlib-1.3.61.jar"/>
<library name="kotlin-stdlib-common-1.3.61.jar"/>
<library name="annotations-13.0.jar"/>
+ <library name="okhttp-brotli-4.3.1.jar"/>
+ <library name="dec-0.1.2.jar"/>
</runtime>
<requires>
diff --git a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java
index b4edb198d..708863b18 100644
--- a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java
+++ b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java
@@ -56,6 +56,7 @@ import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
+import okhttp3.brotli.BrotliInterceptor;
public class OkHttp extends HttpBase {
@@ -216,6 +217,9 @@ public class OkHttp extends HttpBase {
builder.addNetworkInterceptor(new HTTPHeadersInterceptor());
}
+ // enable support for Brotli compression (Content-Encoding)
+ builder.addInterceptor(BrotliInterceptor.INSTANCE);
+
client = builder.build();
}