Skip to content

Conversation

@fabiobento512
Copy link
Contributor

@fabiobento512 fabiobento512 commented Aug 17, 2025

I was missing a way to select a preferred compression type server side. Currently the first compression type supported by both the client and the server is selected, usually browsers send brotli as last, which resulted in gzip to always be favored over it.

I added a new List that allows us to specify our preference on the server side by priority (according to the order of the elements in the list).

I never programmed in Kotlin and it's my first contribution to this project, so please guide me how to get the pull request ready to merge.

@fabiobento512 fabiobento512 force-pushed the master branch 2 times, most recently from 7c26bf0 to 3dc338b Compare August 17, 2025 16:41
@fabiobento512 fabiobento512 marked this pull request as draft August 17, 2025 16:42
@fabiobento512 fabiobento512 force-pushed the master branch 2 times, most recently from 182bcb5 to 7fc1994 Compare August 17, 2025 18:31
@fabiobento512
Copy link
Contributor Author

I tried to add some tests, but I am unable to fix these tests that are failing:
[ERROR] Run 1: TestCompression.assure preferred compressor is respected (gzip):487 » Runtime java.lang.Exception: Assertion error: expected: "gzip" but was: "br" [ERROR] Run 2: TestCompression.assure preferred compressor is respected (gzip):487 » Runtime java.lang.Exception: Assertion error: expected: "gzip" but was: "br" [ERROR] Run 3: TestCompression.assure preferred compressor is respected (gzip):487 » Runtime java.lang.Exception: Assertion error: expected: "gzip" but was: "br"

Basically I set the preferred list to this:

preferredCompressors(listOf(
        CompressionType.GZIP, CompressionType.BR
    )

so GZIP is preferred over Brotli, but for some reason I am getting Brotli as response (even when the request is send with both gzip and br), is the findMatchingCompressor function that I edited in JettyPrecompressingResourceHandler.kt being called for this test? Could you help me fixing this one?

@fabiobento512 fabiobento512 marked this pull request as ready for review August 17, 2025 18:38
@tipsy
Copy link
Member

tipsy commented Aug 18, 2025

Could you help me fixing this one?

Hi @fabiobento512 - it looks like you only added this for precompressed files, I think you are probably testing this for "live" compression in your tests.

@fabiobento512
Copy link
Contributor Author

fabiobento512 commented Aug 18, 2025

Could you help me fixing this one?

Hi @fabiobento512 - it looks like you only added this for precompressed files, I think you are probably testing this for "live" compression in your tests.

Thank you! That was it! The tests that I initially mentioned are now passing. Please have a look at all the changes and see if there is still something else that needs work. 🙂

@tipsy
Copy link
Member

tipsy commented Sep 21, 2025

@fabiobento512 looks good ! There is a bit of duplication here, could you rewrite to remove it?

@fabiobento512 fabiobento512 force-pushed the master branch 3 times, most recently from 2aedbde to 34362ce Compare September 21, 2025 18:29
@fabiobento512
Copy link
Contributor Author

@fabiobento512 looks good ! There is a bit of duplication here, could you rewrite to remove it?

Thanks! I have now tried to remove the code duplication. Please check if it is ok (I moved a common function to the CompressionStrategy class).

@codecov
Copy link

codecov bot commented Sep 21, 2025

Codecov Report

❌ Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.47%. Comparing base (f840be8) to head (f91b2b3).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...avalin/jetty/JettyPrecompressingResourceHandler.kt 33.33% 1 Missing and 1 partial ⚠️
...in/java/io/javalin/compression/CompressedStream.kt 0.00% 0 Missing and 1 partial ⚠️
...java/io/javalin/compression/CompressionStrategy.kt 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2427      +/-   ##
============================================
- Coverage     86.47%   86.47%   -0.01%     
- Complexity     1432     1437       +5     
============================================
  Files           147      147              
  Lines          4600     4607       +7     
  Branches        479      481       +2     
============================================
+ Hits           3978     3984       +6     
  Misses          404      404              
- Partials        218      219       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tipsy
Copy link
Member

tipsy commented Sep 21, 2025

Looks great, thank you very much @fabiobento512 - this will be part of Javalin 7!

@tipsy tipsy merged commit 0f186da into javalin:master Sep 21, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants