offline_web_proxy library

offline_web_proxy

Flutter WebView内で動作するオフライン対応ローカルプロキシサーバ。 既存のWebシステムをモバイルアプリでシームレスに動作させ、 オンライン/オフライン状態を意識する必要をなくします。

主な機能

  • インテリジェントキャッシング: RFC準拠のキャッシュ制御とオフライン戦略
  • リクエストキューイング: オフライン時のPOST/PUT/DELETEリクエストの自動キュー。 キュー・隔離・ドロップ履歴は AES-256 で暗号化して保存し、隔離と履歴には保持上限を設ける
  • Cookie管理: AES-256暗号化による安全なCookie永続化
  • 静的リソース配信: assets/static/ 配下を起動時に走査し、同梱アセットとして配信
  • シームレスなオフライン対応: 透過的なオンライン/オフライン切り替え

クイックスタート

import 'package:offline_web_proxy/offline_web_proxy.dart';

final proxy = OfflineWebProxy();
final config = ProxyConfig(
  origin: 'https://your-api-server.com',
  port: 0, // ポート自動割り当て
  preferredPort: 8787, // 利用可能なら固定ポートを優先する
);

// プロキシサーバを起動
final port = await proxy.start(config: config);
print('Proxy running on http://127.0.0.1:$port');

// WebViewで使用
webViewController.loadUrl('http://127.0.0.1:$port/your-app-path');

アーキテクチャ

プロキシはWebViewからのHTTPリクエストを横取りして:

  1. オンライン時: リクエストを上流サーバに転送し、レスポンスをキャッシュ
  2. オフライン時: キャッシュから配信、または更新リクエストをキューに保存
  3. 復旧時: オンライン復帰時にキューされたリクエストを自動的に消化

キャッシュ戦略

  • Fresh: TTL内、即座に配信
  • Stale: TTL切れだがStale期間内、オンラインなら検証
  • Expired: Stale期間外、クリーンアップ時に削除

設定オプションは ProxyConfig を、詳細な技術仕様は specs.md を参照してください。

Classes

CacheEntry
キャッシュエントリの情報を表すクラス
CacheStats
キャッシュシステム固有の統計情報を表すクラス
CookieInfo
保存されているCookieの情報を表すクラス(値はセキュリティ上マスクされる)
CookieRestoreEntry
外部から復元する Cookie 情報を表します。
DroppedRequest
エラーによりキューからドロップされたリクエストの履歴を表すクラス
EncryptedStorageRecoveryResult
暗号化した保存領域の復旧 API の結果です。
OfflineWebProxy
Flutter WebView内で動作するオフライン対応ローカルプロキシサーバ。 WebViewからのリクエストを横取りし、ネットワーク接続状態に基づいて インテリジェントに処理を行うローカルHTTPサーバを作成します。
ProxyConfig
Configuration settings for the OfflineWebProxy server.
ProxyDiagnostics
死活監視と復旧の診断情報を表すクラスです。
ProxyEvent
プロキシサーバのイベント情報を表すクラス(リアルタイム監視用)
ProxyLifecycleGuard
アプリのライフサイクルに連動して proxy の稼働確認と復旧を行うオブザーバです。
ProxyNavigationResolution
WebView 遷移先の解決結果を表すクラスです。
ProxyRecoveryResult
稼働確認と復旧処理の結果を表すクラスです。
ProxyResponseConfig
A response the proxy generates on its own instead of forwarding upstream.
ProxyStats
Statistics and performance metrics for the OfflineWebProxy server.
ProxyWebViewNavigationRecommendation
WebView delegate 向けの推奨処理結果です。
QuarantinedRequest
上流に拒否され、隔離領域へ退避した更新系リクエストを表すクラス
QueuedRequest
オフライン時にキューイングされたリクエストの情報を表すクラス
QueueExcludeRule
An update request that must not be stored in the offline queue.
QueueResendResult
Outcome of one attempt to resend a queued update request.
Semaphore
並行性制御用のセマフォクラス。
WarmupEntry
個別パスの更新結果
WarmupResult
キャッシュ事前更新(Warmup)処理の結果を表すクラス

Enums

CacheStatus
キャッシュの状態
DropPolicy
How the proxy handles a queued update request the upstream rejected.
OnlineDecisionSource
What the current link-layer online decision is based on.
ProxyEventType
プロキシイベントの種別
ProxyNavigationDisposition
WebView 遷移先の取り扱い種別です。
ProxyNavigationReason
WebView 遷移先の判定理由です。
ProxyRecoveryCause
稼働確認と復旧処理の判定種別です。
ProxyStorageBox
proxy が暗号化して保存する Box の種類です。
ProxyWebViewNavigationAction
WebView delegate 向けの推奨アクションです。
StorageBoxCheckResult
暗号化 Box のファイルを、secure storage の鍵と照合した結果です。
StorageIntegrityFailure
暗号化した保存領域を使えない理由、または Cookie Box を破棄した理由です。
StorageRecoveryRejection
暗号化した保存領域の復旧 API が処理を行わなかった理由です。
UpstreamCircuitState
State of the upstream reachability circuit breaker.

Typedefs

ProxyCurrentUrlProvider = String? Function()
現在表示中の URL を返すコールバック関数です。
ProxyRecoveryCallback = void Function(ProxyRecoveryResult result)
復旧結果を受け取るコールバック関数です。
WarmupErrorCallback = void Function(String path, String error)
キャッシュ事前更新でエラーが発生した際に呼ばれるコールバック関数。
WarmupProgressCallback = void Function(int completed, int total)
キャッシュ事前更新の進捗を通知するコールバック関数。

Exceptions / Errors

CacheOperationException
Exception thrown when cache operations fail.
CookieOperationException
Exception thrown when cookie operations fail.
NetworkException
Exception thrown when network operations fail.
PortBindException
Exception thrown when unable to bind to the specified network port.
ProxyStartException
Exception thrown when proxy server fails to start.
ProxyStopException
Exception thrown when proxy server fails to stop cleanly.
QueueOperationException
Exception thrown when offline request queue operations fail.
StatsOperationException
Exception thrown when statistics collection or retrieval fails.
StorageIntegrityException
Exception thrown when the encrypted storage cannot be used.
StorageRecoveryException
Exception thrown when recovering the encrypted storage fails unexpectedly.
WarmupException
Exception thrown when cache warmup operations fail.