rxnet_plus 0.7.2
rxnet_plus: ^0.7.2 copied to clipboard
Flexible network request framework with pluggable adapters (Dio, http, or custom), supporting various caching strategies
0.7.2 #
Breaking Changes #
- Secure defaults -
RxNetConfig.isDebugnow defaults tofalse; debug logging must be enabled explicitly. request()semantics - Returns the final cache/network/retry result. Cache-first modes now perform the network request; retries are no longer cut off by the first failure. Loop mode still returns the first result.- Retry filtering - By default, POST/PATCH are not retried. Use
RetryPolicy.retryOnNonIdempotentto opt in; 4xx (except 408/429), cancellation and parsing errors are never retried. - Cache keys - Path-based cache keys are always SHA-256 hashed (32 hex chars). Existing caches become misses once.
- Interceptor API -
AdapterInterceptormethods returnFutureOr<void>; async interceptors are awaited. Existingvoidimplementations remain compatible. - Token refresh -
TokenRefreshInterceptornow retries the original request throughErrorInterceptorHandler.retryinstead of returning a synthetic response. AdapterResponse.successOverride- Added sovalidateStatusdecisions survive the adapter boundary.
Fixed #
RxNet.initnow honorsconfig.adapter.setEnv/setDefaultEnvupdate the actual request base URL.- Network cache writes go through
RxNetCache, enabling metadata and LRU/LFU/FIFO eviction. - Default timeouts (connect 15s / receive 30s / send 30s) and request-level timeouts.
- URL normalization preserves
//in query/fragment. - Download/upload now run interceptors in Dio/Http adapters.
- DioAdapter supports
dart:io Filerequest bodies. - Cancel-token callbacks are removed when requests finish.
REQUEST_FAILED_READ_CACHEno longer emits both success and failure callbacks.- Binary responses are skipped by the JSON cache.
Security #
- Log redaction covers headers, bodies, PII keys, sensitive URL query parameters and
token=xxxtext. - Certificate pinning examples no longer bypass validation.
- Debug logging is off by default and
LogUtil.erespects the debug flag.
Engineering #
- Corrected
flutter.plugin.implementsplacement and removed placeholder platform config. - Updated
flutter_lintsto ^5.0.0 and added a CI workflow with analyze/test/coverage. - Full-platform conditional imports - Web/Wasm default branches +
dart.library.iofor IO;rxnet_libconditionally exportsIOClient/IOHttpClientAdapter. Verified with actual Web and Windows debug builds. Added a Web compile smoke target to CI. - Example SDK lower bound aligned to
>=3.5.0. - Example rebuilt - Added a responsive Material 3 Playground (all HTTP methods, query/body/header editors, cache/retry/timeout/cancel, generated code), Methods, Recipes, Logs and About pages; legacy demos remain accessible.
- Removed generated HarmonyOS build artifacts from the repository index.
- Fixed stale
DeduplicateInterceptor/ThrottleInterceptor/ZipRequestdocs. ZipRequestErrornow implementsException; cancellation/timeout use consistentZipRequestErrorcontext.
Migration #
See MIGRATION_GUIDE_0.7.2.md or 迁移指南_0.7.2.md.
0.7.1 #
Fixed #
-
Web compile failure (dart2js) - Corrected a wrong conditional-import path in
rxnet_log_adapter_interceptor.dart- 0.7.0 bug: used
../../src/adapter/implementations/http_adapter_web_stub.dart, which resolved to a non-existentsrc/src/...path and broke Web builds - Fix: use
../../adapter/implementations/http_adapter_web_stub.dart - Action: If you are on 0.7.0 and targeting Web, upgrade to 0.7.1 (or later)
- 0.7.0 bug: used
-
HttpAdapter Web name clash - Avoid
IOClientbeing imported from bothpackage:httpand the Web stub- Default client creation is now split via conditional imports (
http_adapter_io.dart/http_adapter_web.dart)
- Default client creation is now split via conditional imports (
Migration #
Drop-in upgrade from 0.7.0. No API changes.
dependencies:
rxnet_plus: ^0.7.1
0.7.0 #
New Features #
-
RxNetConfig Configuration Class - Clean, type-safe configuration with Builder pattern
RxNetConfigreplaces long parameter lists with a structured config object- Builder pattern:
RxNetConfig.builder().baseUrl('...').cacheMode(...).build() copyWith()for immutable config modifications- 100% backward compatible - old
initNet()parameters still work
-
Cache Eviction Policies - Automatic cache size management
cacheMaxSize- Maximum number of cache entries (0 = unlimited)CacheEvictionPolicy.lru- Least Recently Used evictionCacheEvictionPolicy.lfu- Least Frequently Used evictionCacheEvictionPolicy.fifo- First In First Out evictionCacheMetadatatracks createdAt, lastAccessedAt, accessCount per entry- Automatic eviction on every cache write when size exceeds limit
-
RetryPolicy - Advanced retry strategies beyond fixed interval
RetryStrategy.fixed- Fixed interval (default, backward compatible)RetryStrategy.exponentialBackoff- Delay doubles each attemptRetryStrategy.exponentialBackoffWithJitter- Exponential + random jittermaxIntervalcap to prevent excessive delays- Factory methods:
RetryPolicy.fixed(),RetryPolicy.exponentialBackoff(),RetryPolicy.exponentialBackoffWithJitter()
-
AdapterBaseOptions - Adapter-agnostic global request defaults
- Set connectTimeout, receiveTimeout, sendTimeout globally
- Set default headers, contentType, responseType
- Configurable followRedirects, maxRedirects, persistentConnection
- Applied via
RxNetConfig(adapterBaseOptions: ...)or Builder
-
TokenRefreshInterceptor - Automatic token refresh on auth errors
- Detects 401/403 responses and triggers token refresh
- Concurrent refresh deduplication (only one refresh call at a time)
- Customizable
isUnauthorizedcallback onRequestUpdatedcallback to inject new token into request- Lifecycle callbacks:
onTokenRefreshing,onTokenRefreshed,onTokenRefreshFailed
-
DeduplicateInterceptor - Request deduplication within time window
- Prevents duplicate requests with same path within configurable window
- Automatically allows requests after window expires
-
ThrottleInterceptor - Request rate limiting
- Rejects requests within throttle window after the first pass-through
- Configurable throttle duration
-
Cache Clearing by Prefix/Pattern - Granular cache management
cacheManager.clearByPrefix(prefix)- Clear all entries matching prefixcacheManager.clearByPattern(pattern)- Clear all entries matching regex
-
RxResult Improvements - Safer result handling
RxResult.success(value)factory - Guaranteed non-null valuerequiredValuegetter - Throws StateError if error or null
Improved #
- BuildRequest Cache Integration - Cache operations now use
RxNetCachedirectly- Cache reads/writes go through
RxNetCache.saveNetworkCache()/readNetworkCache() - Eviction policies enforced automatically on cache writes
- Cache reads/writes go through
Changed #
- Database Metadata Store -
RxNetDataBasenow supports metadata storageputMetadata()/getMetadata()/deleteMetadata()/getAllMetadata()/cleanMetadata()- Separate Sembast store for cache metadata (eviction tracking)
Migration Guide #
100% backward compatible - No code changes required. New features are opt-in.
New: RxNetConfig (recommended)
Before:
await RxNet.init(
baseUrl: "https://api.example.com",
cacheMode: CacheMode.CACHE_EMPTY_OR_EXPIRED_THEN_REQUEST,
cacheInvalidationTime: 60000,
interceptors: [RxNetLogAdapterInterceptor()],
);
After:
await RxNet.init(config: RxNetConfig(
baseUrl: "https://api.example.com",
cacheMode: CacheMode.CACHE_EMPTY_OR_EXPIRED_THEN_REQUEST,
cacheInvalidationTime: 60000,
interceptors: [RxNetLogAdapterInterceptor()],
cacheMaxSize: 500,
cacheEvictionPolicy: CacheEvictionPolicy.lru,
adapterBaseOptions: AdapterBaseOptions(
connectTimeout: Duration(seconds: 10),
receiveTimeout: Duration(seconds: 30),
),
));
New: RetryPolicy
Before:
RxNet.get()
.setPath("/api/data")
.setRetryCount(3, interval: Duration(seconds: 2))
.request();
After:
RxNet.get()
.setPath("/api/data")
.setRetryPolicy(RetryPolicy.exponentialBackoff(
maxRetries: 3,
baseInterval: Duration(seconds: 1),
maxInterval: Duration(seconds: 10),
))
.request();
0.6.2 #
0.6.1 #
New Features #
- Concurrent Callback Requests - Execute multiple callback-based requests in parallel
- Sembast Database - Replaced Hive with pure Dart database solution
Fixed #
- Breakpoint Download Fixes - Works correctly with all adapters
- HttpAdapter Improvements - Multipart upload, stream responses, progress tracking
- URL Path Normalization - Fixed multiple slashes in request URLs
- Web Platform Support - Fixed adapters on Web platform
0.6.0 #
Added #
- Pluggable Adapter Architecture - DioAdapter, HttpAdapter, MockAdapter
- Unified Interceptor System - Adapter-agnostic AdapterInterceptor interface
- Custom Adapter Support - Implement NetworkAdapter interface
0.5.0 #
- Parameter type separation - Path, query, and body parameters
- RESTful automatic detection - No manual settings required
- API semantic improvement - More intuitive method names
- Low-level reconstruction - Updated BuildRequest
0.4.x #
- Generic request support with type conversion
- RESTFul @path style request support
- Overall architecture redesign