Skip to content

Commit

Permalink
Synchronize HttpHeaderNames with Guava (#5789)
Browse files Browse the repository at this point in the history
Motivation:

`HttpHeaderNamesTest` failed locally because we omitted three headers
when upgrading the Guava version to 33.2.0.

We can't detect the problem from our CI builds since all fields of Guava
`HttpHeaders` are removed by the `trimShadedJar` task on which the
`build` task depends. The fields are actually used for testing.

Modifications:

- Keep `HttpHeaders` and `MediaType` of Guava from trimming to avoid
unexpected test results.
- Add `-PpreferShadedTests=<boolean>` option to run unshaded tests along
with shaded tests
- This option is disabled by default to avoid running the same tests
twice.
- Add missing headers to `HttpHeaderNames`

Result:

New headers from Guava have been added to `HttpHeaderNames`.
  • Loading branch information
ikhoon authored Jun 28, 2024
1 parent cbab1c4 commit 206f4e4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/actions_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ jobs:
-PbuildJdkVersion=${{ env.BUILD_JDK_VERSION }} \
-PtestJavaVersion=${{ matrix.java }} \
${{ matrix.min-java && format('-PminimumJavaVersion={0}', matrix.min-java) || '' }} \
-Porg.gradle.java.installations.paths=${{ steps.setup-build-jdk.outputs.path }},${{ steps.setup-jdk.outputs.path }}
-Porg.gradle.java.installations.paths=${{ steps.setup-build-jdk.outputs.path }},${{ steps.setup-jdk.outputs.path }} \
-PpreferShadedTests=${{ github.ref_name != 'main' }}
# Unshaded tests are skipped for PRs to avoid running the same tests twice.
shell: bash
env:
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
Expand Down
3 changes: 3 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ if (tasks.findByName('trimShadedJar')) {
keep "class com.linecorp.armeria.internal.shaded.bouncycastle.jcajce.provider.asymmetric.ec.** { *; }"
keep "class com.linecorp.armeria.internal.shaded.bouncycastle.jcajce.provider.asymmetric.rsa.** { *; }"
keep "class com.linecorp.armeria.internal.shaded.bouncycastle.jcajce.provider.asymmetric.x509.** { *; }"
// Keep the Guava classes accessed during testing.
keep "class com.linecorp.armeria.internal.shaded.guava.net.HttpHeaders { *; }"
keep "class com.linecorp.armeria.internal.shaded.guava.net.MediaType { *; }"
dontnote
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,12 @@ public final class HttpHeaderNames {
* header field name.
*/
public static final AsciiString PERMISSIONS_POLICY = create("Permissions-Policy");
/**
* The HTTP <a
* href="https://w3c.github.io/webappsec-permissions-policy/#permissions-policy-report-only-http-header-field">{@code
* Permissions-Policy-Report-Only}</a> header field name.
*/
public static final AsciiString PERMISSIONS_POLICY_REPORT_ONLY = create("Permissions-Policy-Report-Only");
/**
* The HTTP <a
* href="https://datatracker.ietf.org/doc/html/rfc8942">{@code
Expand Down Expand Up @@ -904,24 +910,33 @@ public final class HttpHeaderNames {
* Observe-Browsing-Topics}</a> header field name.
*/
public static final AsciiString OBSERVE_BROWSING_TOPICS = create("Observe-Browsing-Topics");
/**
* The HTTP <a href="https://datatracker.ietf.org/doc/html/rfc8586">{@code CDN-Loop}</a> header field name.
*/
public static final AsciiString CDN_LOOP = create("CDN-Loop");

/**
* The HTTP <a
* href="https://wicg.github.io/turtledove/#handling-direct-from-seller-signals">{@code
* Sec-Ad-Auction-Fetch}</a> header field name.
*/
public static final AsciiString SEC_AD_AUCTION_FETCH = create("Sec-Ad-Auction-Fetch");

/**
* The HTTP <a
* href="https://privacycg.github.io/gpc-spec/#the-sec-gpc-header-field-for-http-requests">{@code
* Sec-GPC}</a> header field name.
*/
public static final AsciiString SEC_GPC = create("Sec-GPC");
/**
* The HTTP <a
* href="https://wicg.github.io/turtledove/#handling-direct-from-seller-signals">{@code
* Ad-Auction-Signals}</a> header field name.
*/
public static final AsciiString AD_AUCTION_SIGNALS = create("Ad-Auction-Signals");
/**
* The HTTP <a href="https://wicg.github.io/turtledove/#http-headerdef-ad-auction-allowed">{@code
* Ad-Auction-Allowed}</a> header field name.
*/
public static final AsciiString AD_AUCTION_ALLOWED = create("Ad-Auction-Allowed");
/**
* The HTTP <a href="https://datatracker.ietf.org/doc/html/rfc8586">{@code CDN-Loop}</a> header field name.
*/
public static final AsciiString CDN_LOOP = create("CDN-Loop");

private static final Map<CharSequence, AsciiString> map;
private static final Map<AsciiString, String> inverseMap;
Expand Down
3 changes: 3 additions & 0 deletions gradle/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ relocations [ { from: "com.google.common", to: "com.doe.john.myproject.shaded.gu
{ from: "com.google.thirdparty.publicsuffix", to: "com.doe.john.myproject.shaded.publicsuffix" } ]
```

Unshaded tests are disabled by default when a shading task is configured. If you want to run unshaded tests,
you can specify `-PpreferShadedTests=false` option.

### Trimming a shaded JAR with `trim` flag

If you shade many dependencies, your JAR will grow huge, even if you only use
Expand Down
7 changes: 6 additions & 1 deletion gradle/scripts/lib/java-shade.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,13 @@ configure(relocatedProjects) {

gradle.taskGraph.whenReady {
// Skip unshaded tests if shaded tests will run.
// To enable, set the property 'preferShadedTests' to 'false'.
boolean runUnshadedTests = false
if (rootProject.hasProperty('preferShadedTests') && "false" == rootProject.property('preferShadedTests')) {
runUnshadedTests = true
}
if (gradle.taskGraph.hasTask(tasks.shadedTest)) {
tasks.test.onlyIf { false }
tasks.test.onlyIf { runUnshadedTests }
}
}
}
Expand Down

0 comments on commit 206f4e4

Please sign in to comment.