Repository navigation
Drop undecodable codings from Accept-Encoding #2381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pavel-ptashyts
wants to merge
6
commits into
AsyncHttpClient:main
Choose a base branch
from
maygemdev:claude/accept-encoding-filter-113031
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5559e74
Drop undecodable codings from Accept-Encoding
pavel-ptashyts 1a705cf
Merge upstream/main into claude/accept-encoding-filter-113031
pavel-ptashyts f4c709d
Merge upstream/main into claude/accept-encoding-filter-113031
pavel-ptashyts 93f51c0
Keep a zero-weight refusal in Accept-Encoding
pavel-ptashyts d3a31c6
Refuse a dropped coding next to a wildcard
pavel-ptashyts cf07110
Test Accept-Encoding filtering via newNettyRequest
pavel-ptashyts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...rc/test/java/org/asynchttpclient/netty/request/NettyRequestFactoryAcceptEncodingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * Copyright (c) 2026 AsyncHttpClient Project. All rights reserved. | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
| package org.asynchttpclient.netty.request; | ||
|
|
||
| import io.netty.handler.codec.http.DefaultHttpHeaders; | ||
| import io.netty.handler.codec.http.HttpHeaders; | ||
| import org.asynchttpclient.AsyncHttpClientConfig; | ||
| import org.asynchttpclient.DefaultAsyncHttpClientConfig; | ||
| import org.asynchttpclient.RequestBuilder; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static io.netty.handler.codec.http.HttpHeaderNames.ACCEPT_ENCODING; | ||
| import static org.asynchttpclient.netty.request.NettyRequestFactory.filterOutUndecodableAcceptEncodings; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| /** | ||
| * Brotli and zstd are both on the test classpath, so the availability flags are passed in, to the helper or to the | ||
| * factory, rather than taken from Netty's {@code Brotli.isAvailable()} and {@code Zstd.isAvailable()}. | ||
| */ | ||
| public class NettyRequestFactoryAcceptEncodingTest { | ||
|
|
||
| @Test | ||
| public void dropsBothWhenNeitherIsAvailable() { | ||
| assertEquals(List.of("gzip, deflate"), filter(false, false, "gzip, deflate, br, zstd")); | ||
| assertEquals(List.of("gzip, deflate"), filter(false, false, "gzip, deflate, zstd, br")); | ||
| } | ||
|
|
||
| @Test | ||
| public void dropsOnlyTheUnavailableOne() { | ||
| assertEquals(List.of("gzip, deflate, zstd"), filter(false, true, "gzip, deflate, br, zstd")); | ||
| assertEquals(List.of("gzip, deflate, br"), filter(true, false, "gzip, deflate, br, zstd")); | ||
| } | ||
|
|
||
| @Test | ||
| public void leavesHeaderUntouchedWhenBothAreAvailable() { | ||
| assertEquals(List.of("gzip", "br, zstd"), filter(true, true, "gzip", "br, zstd")); | ||
| } | ||
|
|
||
| @Test | ||
| public void leavesHeaderUntouchedWhenNothingIsDropped() { | ||
| assertEquals(List.of("gzip", "deflate"), filter(false, false, "gzip", "deflate")); | ||
| } | ||
|
|
||
| @Test | ||
| public void filtersEveryHeaderFieldAndKeepsTheOthers() { | ||
| assertEquals(List.of("gzip, deflate"), filter(false, false, "gzip", "br", "deflate, zstd")); | ||
| } | ||
|
|
||
| @Test | ||
| public void newRequestDropsTheUnavailableCodingsWithAutomaticDecompression() { | ||
| assertEquals(List.of("gzip, deflate"), newRequest(true, false, false, "gzip, deflate, br, zstd")); | ||
| assertEquals(List.of("gzip, deflate, zstd"), newRequest(true, false, true, "gzip, deflate, br, zstd")); | ||
| assertEquals(List.of("gzip, deflate, br"), newRequest(true, true, false, "gzip, deflate, br, zstd")); | ||
| assertEquals(List.of("gzip, deflate, br, zstd"), newRequest(true, true, true, "gzip, deflate, br, zstd")); | ||
| } | ||
|
|
||
| @Test | ||
| public void newRequestLeavesTheHeaderToTheUserWithoutAutomaticDecompression() { | ||
| assertEquals(List.of("gzip, deflate, br, zstd"), newRequest(false, false, false, "gzip, deflate, br, zstd")); | ||
| } | ||
|
|
||
| @Test | ||
| public void newRequestOffersOnlyAvailableCodingsWhenCompressionIsEnforced() { | ||
| assertEquals(List.of("gzip,deflate"), newRequest(true, false, false)); | ||
| assertEquals(List.of("gzip,deflate", "br"), newRequest(true, true, false)); | ||
| assertEquals(List.of("gzip,deflate", "zstd"), newRequest(true, false, true)); | ||
| } | ||
|
|
||
| private static List<String> newRequest(boolean automaticDecompression, boolean brotliAvailable, boolean zstdAvailable, | ||
| String... acceptEncodings) { | ||
| AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder() | ||
| .setEnableAutomaticDecompression(automaticDecompression) | ||
| .setCompressionEnforced(true) | ||
| .build(); | ||
| RequestBuilder request = new RequestBuilder("GET").setUrl("http://example.com/"); | ||
| for (String acceptEncoding : acceptEncodings) { | ||
| request.addHeader(ACCEPT_ENCODING, acceptEncoding); | ||
| } | ||
| return new NettyRequestFactory(config, brotliAvailable, zstdAvailable) | ||
| .newNettyRequest(request.build(), false, null, null, null) | ||
| .getHttpRequest() | ||
| .headers() | ||
| .getAll(ACCEPT_ENCODING); | ||
| } | ||
|
|
||
| private static List<String> filter(boolean brotliAvailable, boolean zstdAvailable, String... acceptEncodings) { | ||
| HttpHeaders headers = new DefaultHttpHeaders(); | ||
| headers.add(ACCEPT_ENCODING, Arrays.asList(acceptEncodings)); | ||
| filterOutUndecodableAcceptEncodings(headers, brotliAvailable, zstdAvailable); | ||
| return headers.getAll(ACCEPT_ENCODING); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.