Skip to content

Add optional gzip request compression - #347

Open
turtledreams wants to merge 2 commits into
stagingfrom
request-compression
Open

turtledreams wants to merge 2 commits into
stagingfrom
request-compression

Conversation

@turtledreams

Copy link
Copy Markdown
Contributor

Adds optional compression of request bodies.

  • New config method enableRequestCompression(), off by default. It does not apply in backend mode, which does not use the SDK behavior settings.
  • With it on, the SDK behavior settings request carries gzip=1. A server that reads compressed bodies answers with "gzip": true next to c. The SDK keeps that answer in memory and never stores it.
  • Then a POST body between 1 KB and 1 MB (never multipart) is compressed with GZIPOutputStream and sent to the endpoint with content_encoding=gzip as its only query. A body over 1 MB goes plain, because the server refuses a larger compressed body. The Content-Type stays application/x-www-form-urlencoded and no Content-Encoding header is set. A body goes compressed only when it gets smaller.
  • A compressed request that is answered but not accepted stops compression, and the request is retried plain. A compressed immediate request (remote config, feedback widgets) counts as accepted with any JSON answer. Compression starts again when a later SDK behavior settings answer says "gzip": true, or when the SDK starts again. Network errors and timeouts do not stop it.
  • The request queue, storage, checksum and logs keep the plain body.
  • A server without this support never answers "gzip": true, so it keeps getting plain requests.
  • The public API record gains Config.enableRequestCompression() and two default methods of the configuration provider.
Success criterion How it was checked
Option off: no gzip=1, plain bodies JUnit
Server says gzip: a body of 1 KB or more goes to /i?content_encoding=gzip as gzip, decodes to the plain body and carries the plain body's checksum JUnit
Body under 1 KB stays plain JUnit
Server without the gzip key gets plain bodies JUnit
Body over 1 MB stays plain and compression stays on JUnit
Refused compressed request: the retry and later requests go plain JUnit
After a refusal, a new settings answer with gzip turns compression on again JUnit
A compressed immediate request answered with JSON keeps compression on; one answered with a page, an error or nothing stops it JUnit
A compressed request that got no answer keeps compression on JUnit
The gzip answer is not stored with the behavior settings JUnit
After a server URL change, plain until the new server says gzip JUnit
A server with the support stores compressed requests correctly Manual: an event batch and a crash report went as 1,105 and 1,215 bytes of gzip (11,570 and 5,144 plain), both were stored

Tests: RequestCompressionTests (17 tests); ModuleConfigurationTests lists gzip among the top-level answer keys. The full suite (806 tests) passes; the public API record was regenerated with metalava.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

CI report

Check Result Summary
Code Coverage ✅ passed Coverage: Line coverage 90.4% (sdk-java), 70.5% (sdk-java-ui)
CodeQL ✅ passed
Cross Platform Tests ✅ passed
Dependency Security Scan ✅ passed Dependency scan: No blocking vulnerability
Java Gradle Build and Test ✅ passed Unit tests: 806 passed, 0 failed, 0 skipped
Public API changelog ✅ passed
Public API changes ✅ passed Public API: 0 removed or changed, 2 added
Release tools ✅ passed
Static analysis ✅ passed No new findings
Validate Gradle Wrapper Checksum ✅ passed
Code Coverage: Coverage, Line coverage 90.4% (sdk-java), 70.5% (sdk-java-ui)
module lines branches
sdk-java 90.4% (8012/8859) 80.2% (3522/4389)
sdk-java-ui 70.5% (968/1374) 63.2% (499/790)

Files changed by this pull request

file lines covered
sdk-java/src/main/java/ly/count/sdk/java/Config.java 92.1% (314/341)
sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigurationProvider.java 90.5% (19/21)
sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java 86.8% (46/53)
sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java 90.7% (78/86)
sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleConfiguration.java 96.8% (460/475)
sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java 90.2% (293/325)
sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java 93.1% (149/160)

Least covered classes (10 shown)

class module lines covered uncovered
ly.count.sdk.java.ui.JavaFxContentDisplay sdk-java-ui 10.6% (23/216) 193
ly.count.sdk.java.ui.FxSurfaces sdk-java-ui 74.8% (172/230) 58
ly.count.sdk.java.ui.ExternalBrowser sdk-java-ui 55.0% (66/120) 54
ly.count.sdk.java.internal.SDKCore sdk-java 91.1% (471/517) 46
ly.count.sdk.java.ui.JavaFxWidgetHost sdk-java-ui 81.2% (190/234) 44
ly.count.sdk.java.internal.ModuleRequests sdk-java 78.5% (157/200) 43
ly.count.sdk.java.internal.SessionImpl sdk-java 88.4% (304/344) 40
ly.count.sdk.java.internal.Log sdk-java 93.7% (546/583) 37
ly.count.sdk.java.internal.ModuleContent sdk-java 89.7% (280/312) 32
ly.count.sdk.java.internal.TimedEvents sdk-java 60.8% (48/79) 31
Dependency Security Scan: Dependency scan, No blocking vulnerability

Scanned 25 resolved dependencies, failing on HIGH and above.

No known vulnerabilities in 25 resolved dependencies.
Java Gradle Build and Test: Unit tests, 806 passed, 0 failed, 0 skipped

The check run lists every test and each failure.

Public API changes: Public API, 0 removed or changed, 2 added

Added: 2. Check that each one is meant to be public.

ly.count.sdk.java.Config: method public ly.count.sdk.java.Config! enableRequestCompression();
ly.count.sdk.java.Config: field protected boolean requestCompressionEnabled;
Static analysis, No new findings

SpotBugs: 147 findings

Rule Level Count Description
EI_EXPOSE_REP2 note 30 May expose internal representation by incorporating reference to mutable object.
AT_STALE_THREAD_WRITE_OF_PRIMITIVE warning 22 This write of this shared primitive variable may not be visible to other threads.
EI_EXPOSE_REP note 16 May expose internal representation by returning reference to mutable object.
WMI_WRONG_MAP_ITERATOR note 9 Inefficient use of keySet iterator instead of entrySet iterator.
CT_CONSTRUCTOR_THROW note 7 Be wary of letting constructors throw exceptions.
NP_BOOLEAN_RETURN_NULL warning 5 Method with Boolean return type returns explicit null.
URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD note 5 Unread public/protected field.
BX_UNBOXING_IMMEDIATELY_REBOXED note 4 Boxed value is unboxed and then immediately reboxed.
IS2_INCONSISTENT_SYNC note 4 Inconsistent synchronization.
USO_UNSAFE_OBJECT_SYNCHRONIZATION error 4 Use private final lock objects in synchronization blocks.
USO_UNSAFE_STATIC_METHOD_SYNCHRONIZATION error 4 Instead of static synchronized methods, use private final lock objects with block synchronization.
AT_NONATOMIC_64BIT_PRIMITIVE warning 3 This write of this 64-bit primitive variable may not be atomic.
DM_DEFAULT_ENCODING note 3 Reliance on default encoding.
ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD note 3 Write to static field from instance method.
AT_NONATOMIC_OPERATIONS_ON_SHARED_VARIABLE warning 2 Operation on shared variable is not atomic.
DMI_INVOKING_TOSTRING_ON_ARRAY error 2 Invocation of toString on an array.
MS_PKGPROTECT note 2 Field should be package protected.
MS_SHOULD_BE_FINAL note 2 Field isn't final but should be.
NP_NULL_PARAM_DEREF error 2 Method call passes null for non-null parameter.
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE note 2 Redundant nullcheck of value known to be non-null.
USO_UNSAFE_ACCESSIBLE_OBJECT_SYNCHRONIZATION error 2 Use private final lock objects in synchronization blocks when the lock is accessible.
DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE warning 1 Synchronization on boxed primitive.
DMI_RANDOM_USED_ONLY_ONCE warning 1 Random object created and used only once.
ICAST_IDIV_CAST_TO_DOUBLE note 1 Integral division result cast to double or float.
ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND error 1 int value cast to float and then passed to Math.round.
IC_INIT_CIRCULARITY note 1 Initialization circularity.
LI_LAZY_INIT_STATIC warning 1 Incorrect lazy initialization of static field.
LI_LAZY_INIT_UPDATE_STATIC error 1 Incorrect lazy initialization and update of static field.
MS_CANNOT_BE_FINAL note 1 Field isn't final and cannot be protected from malicious code.
NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS error 1 Method call passes null for non-null parameter.
NP_UNWRITTEN_FIELD error 1 Read of unwritten field.
PA_PUBLIC_PRIMITIVE_ATTRIBUTE note 1 Primitive field is public.
UWF_NULL_FIELD warning 1 Field only ever set to null.
UWF_UNWRITTEN_FIELD warning 1 Unwritten field.
VO_VOLATILE_INCREMENT warning 1 An increment to a volatile field isn't atomic.

First 50 findings

Location Rule Message
sdk-java-ui/src/main/java/ly/count/sdk/java/ui/FeedbackWidgetPresenter.java:45 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java-ui/src/main/java/ly/count/sdk/java/ui/FeedbackWidgetPresenter.java:187 RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE Redundant nullcheck of value known to be non-null
sdk-java-ui/src/main/java/ly/count/sdk/java/ui/FxSurfaces.java:303 LI_LAZY_INIT_UPDATE_STATIC Incorrect lazy initialization and update of static field
sdk-java-ui/src/main/java/ly/count/sdk/java/ui/JavaFxContentDisplay.java:97 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/Config.java:178 UWF_NULL_FIELD Field only ever set to null
sdk-java/src/main/java/ly/count/sdk/java/Config.java:305 CT_CONSTRUCTOR_THROW Be wary of letting constructors throw exceptions.
sdk-java/src/main/java/ly/count/sdk/java/Config.java:322 NP_NULL_PARAM_DEREF Method call passes null for non-null parameter
sdk-java/src/main/java/ly/count/sdk/java/Config.java:324 CT_CONSTRUCTOR_THROW Be wary of letting constructors throw exceptions.
sdk-java/src/main/java/ly/count/sdk/java/Config.java:400 AT_NONATOMIC_OPERATIONS_ON_SHARED_VARIABLE Operation on shared variable is not atomic
sdk-java/src/main/java/ly/count/sdk/java/Config.java:425 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:451 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:485 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:513 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:546 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:558 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:568 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:583 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:689 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:721 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:735 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:801 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:818 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:836 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:854 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:1031 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/Config.java:1253 EI_EXPOSE_REP May expose internal representation by returning reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/Config.java:1262 EI_EXPOSE_REP May expose internal representation by returning reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/Config.java:1410 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/Config.java:1415 EI_EXPOSE_REP May expose internal representation by returning reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/Countly.java:38 IC_INIT_CIRCULARITY Initialization circularity
sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java:19 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/CountlyTimer.java:12 MS_SHOULD_BE_FINAL Field isn't final but should be
sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java:46 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java:66 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java:68 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java:95 WMI_WRONG_MAP_ITERATOR Inefficient use of keySet iterator instead of entrySet iterator
sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java:234 EI_EXPOSE_REP May expose internal representation by returning reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java:239 EI_EXPOSE_REP May expose internal representation by returning reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/CrashImpl.java:382 EI_EXPOSE_REP May expose internal representation by returning reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/DefaultNetworking.java:47 AT_STALE_THREAD_WRITE_OF_PRIMITIVE This write of this shared primitive variable may not be visible to other threads
sdk-java/src/main/java/ly/count/sdk/java/internal/DefaultNetworking.java:56 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/DefaultNetworking.java:482 EI_EXPOSE_REP May expose internal representation by returning reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java:19 MS_CANNOT_BE_FINAL Field isn't final and cannot be protected from malicious code
sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java:44 ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD Write to static field from instance method
sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java:48 EI_EXPOSE_REP2 May expose internal representation by incorporating reference to mutable object
sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java:109 WMI_WRONG_MAP_ITERATOR Inefficient use of keySet iterator instead of entrySet iterator
sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java:100 PA_PUBLIC_PRIMITIVE_ATTRIBUTE Primitive field is public
sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java:133 ICAST_IDIV_CAST_TO_DOUBLE Integral division result cast to double or float
sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java:163 DMI_INVOKING_TOSTRING_ON_ARRAY Invocation of toString on an array
sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java:195 WMI_WRONG_MAP_ITERATOR Inefficient use of keySet iterator instead of entrySet iterator

New compared with the base branch: 0

No finding that the base branch does not have.

For 9539040, updated 2026-11-18 04:31 UTC. Each check's run page has its full log.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Dependency security scan

Scanned 25 resolved dependencies, failing on HIGH and above.

No known vulnerabilities in 25 resolved dependencies.

Result: passed

Full run log

@github-actions

Copy link
Copy Markdown

Public API changes

Added: 2. Check that each one is meant to be public.

ly.count.sdk.java.Config: method public ly.count.sdk.java.Config! enableRequestCompression();
ly.count.sdk.java.Config: field protected boolean requestCompressionEnabled;

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Unit Test Results 🚀

806 tests  +17   806 ✅ +17   2m 56s ⏱️ ±0s
 69 suites + 1     0 💤 ± 0 
 69 files   + 1     0 ❌ ± 0 

Results for commit 9539040. ± Comparison against base commit 79d9356.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Code coverage

module lines branches
sdk-java 90.4% (8012/8859) 80.2% (3522/4389)
sdk-java-ui 70.5% (968/1374) 63.2% (499/790)

Files changed by this pull request

file lines covered
sdk-java/src/main/java/ly/count/sdk/java/Config.java 92.1% (314/341)
sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigurationProvider.java 90.5% (19/21)
sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java 86.8% (46/53)
sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java 90.7% (78/86)
sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleConfiguration.java 96.8% (460/475)
sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java 90.2% (293/325)
sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java 93.1% (149/160)
Least covered classes (10 shown)
class module lines covered uncovered
ly.count.sdk.java.ui.JavaFxContentDisplay sdk-java-ui 10.6% (23/216) 193
ly.count.sdk.java.ui.FxSurfaces sdk-java-ui 74.8% (172/230) 58
ly.count.sdk.java.ui.ExternalBrowser sdk-java-ui 55.0% (66/120) 54
ly.count.sdk.java.internal.SDKCore sdk-java 91.1% (471/517) 46
ly.count.sdk.java.ui.JavaFxWidgetHost sdk-java-ui 81.2% (190/234) 44
ly.count.sdk.java.internal.ModuleRequests sdk-java 78.5% (157/200) 43
ly.count.sdk.java.internal.SessionImpl sdk-java 88.4% (304/344) 40
ly.count.sdk.java.internal.Log sdk-java 93.7% (546/583) 37
ly.count.sdk.java.internal.ModuleContent sdk-java 89.7% (280/312) 32
ly.count.sdk.java.internal.TimedEvents sdk-java 60.8% (48/79) 31

Full run log

This branch has not been deployed

No deployments
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.

1 participant