|
37 | 37 | (def ^:private ^AsciiString head-method (AsciiString. "HEAD"))
|
38 | 38 | (def ^:private ^AsciiString connect-method (AsciiString. "CONNECT"))
|
39 | 39 |
|
40 |
| -(defn- contains-class? |
41 |
| - "Returns true if the class is in the array" |
42 |
| - [^"[Lio.netty.handler.codec.compression.CompressionOptions;" a ^Class klazz] |
43 |
| - (let [len (alength a)] |
44 |
| - (loop [i 0] |
45 |
| - (if (>= i len) |
46 |
| - false |
47 |
| - (if (.equals klazz (class (aget ^"[Lio.netty.handler.codec.compression.CompressionOptions;" a i))) |
48 |
| - true |
49 |
| - (recur (unchecked-inc-int i))))))) |
50 |
| - |
51 | 40 | (def ^"[Lio.netty.handler.codec.compression.CompressionOptions;"
|
52 | 41 | available-compressor-options
|
53 | 42 | "A Java array of all available compressor options"
|
|
77 | 66 |
|
78 | 67 | (defrecord Qvals [^double star ^double br ^double snappy ^double zstd ^double gzip ^double deflate])
|
79 | 68 |
|
80 |
| -;; We can't reference these options classes directly in `choose-codec` since the compiler would try |
81 |
| -;; to initialize them even when the necessary dependencies aren't available, resulting in an |
82 |
| -;; error. Indirectly referencing them like this works, though. See |
83 |
| -;; https://github.com/clj-commons/aleph/issues/703 |
84 |
| -(def brotli-options-class |
85 |
| - BrotliOptions) |
86 |
| - |
87 |
| -(def zstd-options-class |
88 |
| - ZstdOptions) |
89 |
| - |
90 | 69 | (defn choose-codec
|
91 | 70 | "Based on Netty's algorithm, which only compares with the next-best option.
|
92 | 71 | E.g., Brotli's q-value is only compared with zstd, not gzip or deflate.
|
|
103 | 82 | ;; some encodings were listed
|
104 | 83 | (cond (and (p/not== br -1.0)
|
105 | 84 | (p/>= br zstd)
|
106 |
| - (contains-class? compressor-options brotli-options-class)) |
| 85 | + (AlephCompressionOptions/hasBrotli compressor-options)) |
107 | 86 | "br"
|
108 | 87 |
|
109 | 88 | (and (p/not== zstd -1.0)
|
110 | 89 | (p/>= zstd snappy)
|
111 |
| - (contains-class? compressor-options zstd-options-class)) |
| 90 | + (AlephCompressionOptions/hasZstd compressor-options)) |
112 | 91 | "zstd"
|
113 | 92 |
|
114 | 93 | (and (p/not== snappy -1.0)
|
115 | 94 | (p/>= snappy gzip)
|
116 |
| - (contains-class? compressor-options SnappyOptions)) |
| 95 | + (AlephCompressionOptions/hasSnappy compressor-options)) |
117 | 96 | "snappy"
|
118 | 97 |
|
119 | 98 | (and (p/not== gzip -1.0)
|
120 | 99 | (p/>= gzip deflate)
|
121 |
| - (contains-class? compressor-options GzipOptions)) |
| 100 | + (AlephCompressionOptions/hasGzip compressor-options)) |
122 | 101 | "gzip"
|
123 | 102 |
|
124 | 103 | (and (p/not== deflate -1.0)
|
125 |
| - (contains-class? compressor-options DeflateOptions)) |
| 104 | + (AlephCompressionOptions/hasDeflate compressor-options)) |
126 | 105 | "deflate")
|
127 | 106 |
|
128 | 107 | ;; no named encodings were listed, so we'll apply *'s qval to unset ones
|
|
0 commit comments