1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
|
From: Markus Koschany <apo@debian.org>
Date: Sun, 13 Nov 2022 15:13:28 +0100
Subject: no brotli support
Requires new build dependency.
Forwarded: not-needed
---
.../org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java
@@ -29,7 +29,6 @@
import java.io.IOException;
import java.io.InputStream;
-import com.aayushatharva.brotli4j.decoder.BrotliInputStream;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -60,6 +59,6 @@
@Override
public InputStream create(final InputStream inputStream) throws IOException {
- return new BrotliInputStream(inputStream);
+ return null;
}
}
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/DeflatingBrotliEntityProducer.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.async.methods;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import com.aayushatharva.brotli4j.encoder.Encoder;
-import com.aayushatharva.brotli4j.encoder.EncoderJNI;
-
-import org.apache.hc.core5.http.Header;
-import org.apache.hc.core5.http.nio.AsyncEntityProducer;
-import org.apache.hc.core5.http.nio.DataStreamChannel;
-import org.apache.hc.core5.util.Args;
-
-/**
- * {@code AsyncEntityProducer} that Brotli-compresses bytes from an upstream producer
- * on the fly and writes the compressed stream to the target {@link DataStreamChannel}.
- * <p>
- * Purely async/streaming: no {@code InputStream}/{@code OutputStream}. Back-pressure is
- * honored via {@link #available()} and the I/O reactor’s calls into {@link #produce(DataStreamChannel)}.
- * Trailers from the upstream producer are preserved and emitted once the compressed output
- * has been fully drained.
- * </p>
- *
- * <p><strong>Content metadata</strong></p>
- * Returns {@code Content-Encoding: br}, {@code Content-Length: -1} and {@code chunked=true}.
- * Repeatability matches the upstream producer.
- *
- * <p><strong>Implementation notes</strong></p>
- * Uses Brotli4j’s {@code EncoderJNI.Wrapper}. JNI-owned output buffers are written directly
- * when possible; if the channel applies back-pressure, the unwritten tail is copied into
- * small pooled direct {@link java.nio.ByteBuffer}s to reduce allocation churn. Native
- * resources are released in {@link #releaseResources()}.
- * <p>
- * Ensure {@link com.aayushatharva.brotli4j.Brotli4jLoader#ensureAvailability()} has been
- * called once at startup; this class also invokes it in a static initializer as a safeguard.
- * </p>
- *
- * @see org.apache.hc.core5.http.nio.AsyncEntityProducer
- * @see org.apache.hc.core5.http.nio.DataStreamChannel
- * @see com.aayushatharva.brotli4j.encoder.EncoderJNI
- * @since 5.6
- */
-public final class DeflatingBrotliEntityProducer implements AsyncEntityProducer {
-
- private enum State { STREAMING, FINISHING, DONE }
-
- private final AsyncEntityProducer upstream;
- private final EncoderJNI.Wrapper encoder;
-
- private ByteBuffer pendingOut;
- private List<? extends Header> pendingTrailers;
- private State state = State.STREAMING;
-
- /**
- * Create a producer with explicit Brotli params.
- *
- * @param upstream upstream entity producer whose bytes will be compressed
- * @param quality Brotli quality level (see brotli4j documentation)
- * @param lgwin Brotli window size log2 (see brotli4j documentation)
- * @param mode Brotli mode hint (GENERIC/TEXT/FONT)
- * @throws IOException if the native encoder cannot be created
- * @since 5.6
- */
- public DeflatingBrotliEntityProducer(
- final AsyncEntityProducer upstream,
- final int quality,
- final int lgwin,
- final Encoder.Mode mode) throws IOException {
- this.upstream = Args.notNull(upstream, "upstream");
- this.encoder = new EncoderJNI.Wrapper(256 * 1024, quality, lgwin, mode);
- }
-
- /**
- * Convenience constructor mapping {@code 0=GENERIC, 1=TEXT, 2=FONT}.
- *
- * @since 5.6
- */
- public DeflatingBrotliEntityProducer(
- final AsyncEntityProducer upstream,
- final int quality,
- final int lgwin,
- final int modeInt) throws IOException {
- this(upstream, quality, lgwin,
- modeInt == 1 ? Encoder.Mode.TEXT :
- modeInt == 2 ? Encoder.Mode.FONT : Encoder.Mode.GENERIC);
- }
-
- /**
- * Create a producer with sensible defaults ({@code quality=5}, {@code lgwin=22}, {@code GENERIC}).
- *
- * @since 5.6
- */
- public DeflatingBrotliEntityProducer(final AsyncEntityProducer upstream) throws IOException {
- this(upstream, 5, 22, Encoder.Mode.GENERIC);
- }
-
-
- @Override
- public String getContentType() {
- return upstream.getContentType();
- }
-
- @Override
- public String getContentEncoding() {
- return "br";
- }
-
- @Override
- public long getContentLength() {
- return -1;
- }
-
- @Override
- public boolean isChunked() {
- return true;
- }
-
- @Override
- public Set<String> getTrailerNames() {
- return upstream.getTrailerNames();
- }
-
- @Override
- public boolean isRepeatable() {
- return upstream.isRepeatable();
- }
-
- @Override
- public int available() {
- if (state == State.DONE) {
- return 0;
- }
- if (pendingOut != null && pendingOut.hasRemaining() || pendingTrailers != null) {
- return 1;
- }
- final int up = upstream.available();
- return (state != State.STREAMING || up > 0) ? 1 : 0;
- }
-
- @Override
- public void produce(final DataStreamChannel channel) throws IOException {
- if (flushPending(channel)) {
- return;
- }
-
- if (state == State.FINISHING) {
- encoder.push(EncoderJNI.Operation.FINISH, 0);
- if (drainEncoder(channel)) {
- return;
- }
- if (pendingTrailers == null) {
- pendingTrailers = Collections.emptyList();
- }
- channel.endStream(pendingTrailers);
- pendingTrailers = null;
- state = State.DONE;
- return;
- }
-
- upstream.produce(new DataStreamChannel() {
- @Override
- public void requestOutput() {
- channel.requestOutput();
- }
-
- @Override
- public int write(final ByteBuffer src) throws IOException {
- int accepted = 0;
- while (src.hasRemaining()) {
- final ByteBuffer in = encoder.getInputBuffer();
- if (!in.hasRemaining()) {
- encoder.push(EncoderJNI.Operation.PROCESS, 0);
- if (drainEncoder(channel)) {
- break;
- }
- continue;
- }
- final int xfer = Math.min(src.remaining(), in.remaining());
- final int lim = src.limit();
- src.limit(src.position() + xfer);
- in.put(src);
- src.limit(lim);
- accepted += xfer;
-
- encoder.push(EncoderJNI.Operation.PROCESS, xfer);
- if (drainEncoder(channel)) {
- break;
- }
- }
- return accepted;
- }
-
- @Override
- public void endStream() throws IOException {
- endStream(Collections.emptyList());
- }
-
- @Override
- public void endStream(final List<? extends Header> trailers) throws IOException {
- pendingTrailers = trailers;
- state = State.FINISHING;
- encoder.push(EncoderJNI.Operation.FINISH, 0);
- if (drainEncoder(channel)) {
- return;
- }
- if (pendingTrailers == null) {
- pendingTrailers = Collections.emptyList();
- }
- channel.endStream(pendingTrailers);
- pendingTrailers = null;
- state = State.DONE;
- }
- });
- }
-
- @Override
- public void failed(final Exception cause) {
- upstream.failed(cause);
- }
-
- @Override
- public void releaseResources() {
- try {
- encoder.destroy();
- } catch (final Throwable ignore) {
- }
- upstream.releaseResources();
- pendingOut = null;
- pendingTrailers = null;
- state = State.DONE;
- }
-
-
- private boolean flushPending(final DataStreamChannel channel) throws IOException {
- if (pendingOut != null && pendingOut.hasRemaining()) {
- channel.write(pendingOut);
- if (pendingOut.hasRemaining()) {
- channel.requestOutput();
- return true;
- }
- pendingOut = null;
- }
- if (pendingOut == null && pendingTrailers != null && state != State.STREAMING) {
- channel.endStream(pendingTrailers);
- pendingTrailers = null;
- state = State.DONE;
- return true;
- }
- return false;
- }
-
- private boolean drainEncoder(final DataStreamChannel channel) throws IOException {
- while (encoder.hasMoreOutput()) {
- final ByteBuffer buf = encoder.pull();
- if (buf == null || !buf.hasRemaining()) {
- continue;
- }
- channel.write(buf);
- if (buf.hasRemaining()) {
- pendingOut = ByteBuffer.allocateDirect(buf.remaining());
- pendingOut.put(buf).flip();
- channel.requestOutput();
- return true;
- }
- }
- return false;
- }
-}
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/BrotliCodecFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/BrotliCodecFactory.java
@@ -31,7 +31,6 @@
import java.io.InputStream;
import java.io.OutputStream;
-import com.aayushatharva.brotli4j.decoder.BrotliInputStream;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.Internal;
@@ -51,7 +50,7 @@
* Creates a lazy decoder that instantiates the Commons Compress stream.
*/
static IOFunction<InputStream, InputStream> decoder() {
- return BrotliInputStream::new;
+ throw new UnsupportedOperationException();
}
/**
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/InflatingBrotliDataConsumer.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.client5.http.async.methods;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.List;
-
-import com.aayushatharva.brotli4j.decoder.DecoderJNI;
-
-import org.apache.hc.core5.http.Header;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.nio.AsyncDataConsumer;
-import org.apache.hc.core5.http.nio.CapacityChannel;
-import org.apache.hc.core5.util.Asserts;
-
-/**
- * {@code AsyncDataConsumer} that inflates a Brotli-compressed byte stream and forwards
- * decompressed bytes to a downstream consumer.
- * <p>
- * Purely async/streaming: no {@code InputStream}/{@code OutputStream}. Back-pressure from
- * the I/O reactor is propagated via {@link CapacityChannel}. JNI output buffers are copied
- * into small reusable direct {@link java.nio.ByteBuffer}s before handing them to the
- * downstream consumer (which may retain them).
- * </p>
- *
- * <p><strong>Implementation notes</strong></p>
- * Uses Brotli4j’s {@code DecoderJNI.Wrapper}. Native resources are released in
- * {@link #releaseResources()}. Throws an {@link java.io.IOException} if the stream is
- * truncated or corrupted.
- * <p>
- * Ensure {@link com.aayushatharva.brotli4j.Brotli4jLoader#ensureAvailability()} has been
- * called once at startup; this class also invokes it in a static initializer as a safeguard.
- * </p>
- *
- * @see org.apache.hc.core5.http.nio.AsyncDataConsumer
- * @see org.apache.hc.core5.http.nio.CapacityChannel
- * @see com.aayushatharva.brotli4j.decoder.DecoderJNI
- * @since 5.6
- */
-public final class InflatingBrotliDataConsumer implements AsyncDataConsumer {
-
- private final AsyncDataConsumer downstream;
- private final DecoderJNI.Wrapper decoder;
- private volatile CapacityChannel capacity;
-
-
- public InflatingBrotliDataConsumer(final AsyncDataConsumer downstream) {
- this.downstream = downstream;
- try {
- this.decoder = new DecoderJNI.Wrapper(8 * 1024);
- } catch (final IOException e) {
- throw new RuntimeException("Unable to initialize DecoderJNI", e);
- }
- }
-
- @Override
- public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
- this.capacity = capacityChannel;
- downstream.updateCapacity(capacityChannel);
- }
-
- @Override
- public void consume(final ByteBuffer src) throws IOException {
- while (src.hasRemaining()) {
- final ByteBuffer in = decoder.getInputBuffer();
- final int xfer = Math.min(src.remaining(), in.remaining());
- if (xfer == 0) {
- decoder.push(0);
- pump();
- continue;
- }
- final int lim = src.limit();
- src.limit(src.position() + xfer);
- in.put(src);
- src.limit(lim);
-
- decoder.push(xfer);
- pump();
- }
- final CapacityChannel ch = this.capacity;
- if (ch != null) {
- ch.update(Integer.MAX_VALUE);
- }
- }
-
- @Override
- public void streamEnd(final List<? extends Header> trailers) throws IOException, HttpException {
- pump();
- Asserts.check(decoder.getStatus() == DecoderJNI.Status.DONE || !decoder.hasOutput(),
- "Truncated brotli stream");
- downstream.streamEnd(trailers);
- }
-
- @Override
- public void releaseResources() {
- try {
- decoder.destroy();
- } catch (final Throwable ignore) {
- }
- downstream.releaseResources();
- }
-
- private void pump() throws IOException {
- for (; ; ) {
- switch (decoder.getStatus()) {
- case OK:
- decoder.push(0);
- break;
- case NEEDS_MORE_OUTPUT: {
- // Pull a decoder-owned buffer; copy before handing off.
- final ByteBuffer nativeBuf = decoder.pull();
- if (nativeBuf != null && nativeBuf.hasRemaining()) {
- final ByteBuffer copy = ByteBuffer.allocateDirect(nativeBuf.remaining());
- copy.put(nativeBuf).flip();
- downstream.consume(copy);
- }
- break;
- }
- case NEEDS_MORE_INPUT:
- if (decoder.hasOutput()) {
- final ByteBuffer nativeBuf = decoder.pull();
- if (nativeBuf != null && nativeBuf.hasRemaining()) {
- final ByteBuffer copy = ByteBuffer.allocateDirect(nativeBuf.remaining());
- copy.put(nativeBuf).flip();
- downstream.consume(copy);
- break;
- }
- }
- return; // wait for more input
- case DONE:
- if (decoder.hasOutput()) {
- final ByteBuffer nativeBuf = decoder.pull();
- if (nativeBuf != null && nativeBuf.hasRemaining()) {
- final ByteBuffer copy = ByteBuffer.allocateDirect(nativeBuf.remaining());
- copy.put(nativeBuf).flip();
- downstream.consume(copy);
- break;
- }
- }
- return;
- default:
- // Corrupted stream
- throw new IOException("Brotli stream corrupted");
- }
- }
- }
-}
\ No newline at end of file
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
@@ -38,11 +38,9 @@
import org.apache.hc.client5.http.async.AsyncExecChain;
import org.apache.hc.client5.http.async.AsyncExecChainHandler;
import org.apache.hc.client5.http.async.methods.InflatingAsyncDataConsumer;
-import org.apache.hc.client5.http.async.methods.InflatingBrotliDataConsumer;
import org.apache.hc.client5.http.async.methods.InflatingGzipDataConsumer;
import org.apache.hc.client5.http.async.methods.InflatingZstdDataConsumer;
import org.apache.hc.client5.http.entity.compress.ContentCoding;
-import org.apache.hc.client5.http.impl.Brotli4jRuntime;
import org.apache.hc.client5.http.impl.ContentCodingSupport;
import org.apache.hc.client5.http.impl.ZstdRuntime;
import org.apache.hc.client5.http.protocol.HttpClientContext;
@@ -108,11 +106,6 @@
tokens.add("zstd");
}
- if (Brotli4jRuntime.available()) {
- rb.register(ContentCoding.BROTLI.token(), InflatingBrotliDataConsumer::new);
- tokens.add(ContentCoding.BROTLI.token());
- }
-
this.decoders = rb.build();
this.acceptTokens = tokens;
this.maxCodecListLen = maxCodecListLen;
|