Skip to content

Commit ea09fc9

Browse files
committed
Revert "Merge pull request #705 from clj-commons/add-brotli-and-zstd-deps"
This reverts commit 544561d, reversing changes made to b5794d4.
1 parent c905153 commit ea09fc9

File tree

4 files changed

+71
-48
lines changed

4 files changed

+71
-48
lines changed

deps.edn

+1-15
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,7 @@
2929
io.netty/netty-resolver {:mvn/version "4.1.108.Final"},
3030
io.netty/netty-resolver-dns {:mvn/version "4.1.108.Final"},
3131
metosin/malli
32-
{:mvn/version "0.15.0", :exclusions [org.clojure/clojure]},
33-
com.aayushatharva.brotli4j/brotli4j {:mvn/version "1.16.0"},
34-
com.aayushatharva.brotli4j/service {:mvn/version "1.16.0"},
35-
com.aayushatharva.brotli4j/native-linux-aarch64
36-
{:mvn/version "1.16.0"},
37-
com.aayushatharva.brotli4j/native-linux-armv7
38-
{:mvn/version "1.16.0"},
39-
com.aayushatharva.brotli4j/native-linux-x86_64
40-
{:mvn/version "1.16.0"},
41-
com.aayushatharva.brotli4j/native-osx-aarch64
42-
{:mvn/version "1.16.0"},
43-
com.aayushatharva.brotli4j/native-osx-x86_64 {:mvn/version "1.16.0"},
44-
com.aayushatharva.brotli4j/native-windows-x86_64
45-
{:mvn/version "1.16.0"},
46-
com.github.luben/zstd-jni {:mvn/version "1.5.6-2"}},
32+
{:mvn/version "0.15.0", :exclusions [org.clojure/clojure]}},
4733
:aliases
4834
{:lein2deps
4935
{:deps

project.clj

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,7 @@
2727
[io.netty/netty-handler-proxy ~netty-version]
2828
[io.netty/netty-resolver ~netty-version]
2929
[io.netty/netty-resolver-dns ~netty-version]
30-
[metosin/malli "0.15.0" :exclusions [org.clojure/clojure]]
31-
;;[com.aayushatharva.brotli4j/all ~brotli-version]
32-
[com.aayushatharva.brotli4j/brotli4j ~brotli-version]
33-
[com.aayushatharva.brotli4j/service ~brotli-version]
34-
[com.aayushatharva.brotli4j/native-linux-aarch64 ~brotli-version]
35-
[com.aayushatharva.brotli4j/native-linux-armv7 ~brotli-version]
36-
[com.aayushatharva.brotli4j/native-linux-x86_64 ~brotli-version]
37-
[com.aayushatharva.brotli4j/native-osx-aarch64 ~brotli-version]
38-
[com.aayushatharva.brotli4j/native-osx-x86_64 ~brotli-version]
39-
[com.aayushatharva.brotli4j/native-windows-x86_64 ~brotli-version]
40-
[com.github.luben/zstd-jni "1.5.6-2"]]
30+
[metosin/malli "0.15.0" :exclusions [org.clojure/clojure]]]
4131
:profiles {:dev {:dependencies [[criterium "0.4.6"]
4232
[cheshire "5.13.0"]
4333
[org.slf4j/slf4j-simple "2.0.12"]
@@ -47,7 +37,17 @@
4737
[org.bouncycastle/bcprov-jdk18on "1.77"]
4838
[org.bouncycastle/bcpkix-jdk18on "1.77"]
4939
;;[org.bouncycastle/bctls-jdk18on "1.75"]
50-
[io.netty/netty-tcnative-boringssl-static "2.0.65.Final"]]
40+
[io.netty/netty-tcnative-boringssl-static "2.0.65.Final"]
41+
;;[com.aayushatharva.brotli4j/all ~brotli-version]
42+
[com.aayushatharva.brotli4j/brotli4j ~brotli-version]
43+
[com.aayushatharva.brotli4j/service ~brotli-version]
44+
[com.aayushatharva.brotli4j/native-linux-aarch64 ~brotli-version]
45+
[com.aayushatharva.brotli4j/native-linux-armv7 ~brotli-version]
46+
[com.aayushatharva.brotli4j/native-linux-x86_64 ~brotli-version]
47+
[com.aayushatharva.brotli4j/native-osx-aarch64 ~brotli-version]
48+
[com.aayushatharva.brotli4j/native-osx-x86_64 ~brotli-version]
49+
[com.aayushatharva.brotli4j/native-windows-x86_64 ~brotli-version]
50+
[com.github.luben/zstd-jni "1.5.6-2"]]
5151
:jvm-opts ["-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"
5252
"-Dorg.slf4j.simpleLogger.showThreadName=false"
5353
"-Dorg.slf4j.simpleLogger.showThreadId=true"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package aleph.http;
2+
3+
import io.netty.handler.codec.compression.BrotliOptions;
4+
import io.netty.handler.codec.compression.DeflateOptions;
5+
import io.netty.handler.codec.compression.GzipOptions;
6+
import io.netty.handler.codec.compression.SnappyOptions;
7+
import io.netty.handler.codec.compression.StandardCompressionOptions;
8+
import io.netty.handler.codec.compression.ZstdOptions;
9+
10+
/**
11+
* {@link AlephCompressionOptions} exists because the Clojure compiler cannot
12+
* distinguish between static fields and static methods without reflection.
13+
*
14+
* This is a problem when using Netty's StandardCompressionOptions, because
15+
* reflection triggers a load of all the methods referencing optional classes,
16+
* which may not exist in the classpath, resulting in a ClassNotFoundException.
17+
*/
18+
public class AlephCompressionOptions {
19+
private AlephCompressionOptions() {
20+
// Prevent outside initialization
21+
}
22+
23+
public static BrotliOptions brotli() {
24+
return StandardCompressionOptions.brotli();
25+
}
26+
27+
public static ZstdOptions zstd() {
28+
return StandardCompressionOptions.zstd();
29+
}
30+
31+
public static SnappyOptions snappy() {
32+
return StandardCompressionOptions.snappy();
33+
}
34+
35+
public static GzipOptions gzip() {
36+
return StandardCompressionOptions.gzip();
37+
}
38+
39+
public static DeflateOptions deflate() {
40+
return StandardCompressionOptions.deflate();
41+
}
42+
}

src/aleph/http/compression.clj

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
(ns ^:no-doc aleph.http.compression
2-
"Currently focused on HTTP/2, since Netty offers better support for
3-
compression in its HTTP/1 code.
2+
"Currently only for HTTP/2, since Netty offers better support for
3+
compression in HTTP/1 code.
44
55
Best supported compression codecs on the web are Brotli, gzip, and deflate.
66
77
Snappy is primarily an internal Google codec, but is supported by some
88
open-source databases. It's not on track to be a web standard, but is
99
well-supported by Netty.
1010
11-
Zstd is a promising Facebook codec that is registered with IANA, but is not
12-
yet widely available. (See https://caniuse.com/zstd).
11+
Zstd is a Facebook codec that is registered with IANA, but is not yet
12+
widely available. (See https://caniuse.com/zstd).
1313
1414
See https://www.iana.org/assignments/http-parameters/http-parameters.xml#content-coding"
1515
(:require
1616
[aleph.netty :as netty]
1717
[clj-commons.primitive-math :as p]
1818
[clojure.tools.logging :as log])
1919
(:import
20+
(aleph.http AlephCompressionOptions)
2021
(io.netty.channel ChannelHandler)
2122
(io.netty.handler.codec.compression
2223
Brotli
23-
BrotliOptions
24-
CompressionOptions
24+
BrotliOptions CompressionOptions
2525
DeflateOptions
2626
GzipOptions
2727
SnappyOptions
28-
StandardCompressionOptions
29-
Zstd
30-
ZstdOptions)
28+
Zstd ZstdOptions)
3129
(io.netty.handler.codec.http HttpHeaderNames)
3230
(io.netty.handler.codec.http2 Http2HeadersFrame)
3331
(io.netty.util AsciiString)
@@ -38,10 +36,6 @@
3836
(def ^:private ^AsciiString head-method (AsciiString. "HEAD"))
3937
(def ^:private ^AsciiString connect-method (AsciiString. "CONNECT"))
4038

41-
;; From 0.7.0-rc2 on, Brotli and Zstd should be available by default
42-
(Brotli/ensureAvailability)
43-
(Zstd/ensureAvailability)
44-
4539
(defn- contains-class?
4640
"Returns true if the class is in the array"
4741
[^"[Lio.netty.handler.codec.compression.CompressionOptions;" a ^Class klazz]
@@ -57,11 +51,11 @@
5751
available-compressor-options
5852
"A Java array of all available compressor options"
5953
(into-array CompressionOptions
60-
[(StandardCompressionOptions/brotli)
61-
(StandardCompressionOptions/deflate)
62-
(StandardCompressionOptions/gzip)
63-
(StandardCompressionOptions/zstd)
64-
(StandardCompressionOptions/snappy)]))
54+
(cond-> [(AlephCompressionOptions/deflate)
55+
(AlephCompressionOptions/gzip)
56+
(AlephCompressionOptions/snappy)]
57+
(Brotli/isAvailable) (conj (AlephCompressionOptions/brotli))
58+
(Zstd/isAvailable) (conj (AlephCompressionOptions/zstd)))))
6559

6660

6761
(defn- qvalue
@@ -122,10 +116,12 @@
122116

123117
;; no named encodings were listed, so we'll apply *'s qval to unset ones
124118
(p/> star 0.0)
125-
(cond (p/== br -1.0)
119+
(cond (and (p/== br -1.0)
120+
(Brotli/isAvailable))
126121
"br"
127122

128-
(p/== zstd -1.0)
123+
(and (p/== zstd -1.0)
124+
(Zstd/isAvailable))
129125
"zstd"
130126

131127
(p/== snappy -1.0)
@@ -219,7 +215,6 @@
219215
(p/== 204 status)
220216
(p/== 304 status)))
221217
(log/debug "Setting content-encoding to:" @encoding)
222-
;; TODO: add "vary" header
223218
(.set headers HttpHeaderNames/CONTENT_ENCODING chosen-encoding))))))
224219

225220
(.write ctx msg promise))))))

0 commit comments

Comments
 (0)