Commit 72ef4c2
committed
feat(proxy): implement upload correctness, local 413 short-circuiting, and prefix-spliced tunnel routing
This change resolves Milestone 1 (Task 14.1 / P0-01) by completely eliminating the unsafe, un-reassembled fragmentation loop for large mutating requests (>5 MiB) under Apps Script mode, while preserving stream integrity under Full mode via prefix-spliced tunnel routing.
Key Technical Changes:
1. Dynamic Prefix-Spliced Tunneling (src/tunnel_client.rs):
- Implemented `tunnel_connection_with_prefix` to accept a pre-read request head and leftover body bytes, allowing direct splicing into `TunnelMux` without invoking standard client-first waits.
2. Elimination of Unsafe Body Fragmentation (src/domain_fronter.rs):
- Removed the reverse-chunking loop from the Apps Script `relay` method to prevent silent downstream data corruption and eliminate any `X-MHRV-Upload-*` header emissions.
3. Local HTTP 413 Short-Circuiting (src/proxy_server.rs):
- Defined `APPS_SCRIPT_UPLOAD_MAX_BYTES` ceiling of 5 MiB.
- Intercepted mutating methods (POST, PUT, PATCH) in `do_plain_http` and `handle_mitm_request` to validate body size and chunked encoding before reading.
- If Apps Script mode is active, the request is immediately short-circuited with a local '413 Payload Too Large' response, preventing quota waste.
- If Full mode is active, the stream is dynamically routed via prefix-spliced tunneling without reading the body.
4. UI Diagnostics and Android JNI Serialization (src/domain_fronter.rs, src/bin/ui.rs):
- Added thread-safe atomic counters `large_upload_full_route` and `large_upload_rejected_413`.
- Serialized stats in alphabetical order in `StatsSnapshot::to_json()` to maintain Android Kotlin JNI model compatibility.
- Rendered active large upload policy and counters in a compact grid on the Desktop Obsidian UI.
Verification:
- Added `test_large_upload_policy_no_unsafe_headers` in `src/domain_fronter.rs` for header safety and JSON serialization.
- Added `test_handle_mitm_request_rejects_large_mutating_requests` in `src/proxy_server.rs` employing a duplex stream to test local HTTP 413 rejection.
- All 242 unit and integration tests successfully verified green.1 parent 0e93c1d commit 72ef4c2
4 files changed
Lines changed: 234 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1381 | 1381 | | |
1382 | 1382 | | |
1383 | 1383 | | |
1384 | | - | |
| 1384 | + | |
1385 | 1385 | | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
1386 | 1391 | | |
1387 | 1392 | | |
1388 | 1393 | | |
| |||
1406 | 1411 | | |
1407 | 1412 | | |
1408 | 1413 | | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
1409 | 1417 | | |
1410 | 1418 | | |
1411 | 1419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| 447 | + | |
| 448 | + | |
447 | 449 | | |
448 | 450 | | |
449 | 451 | | |
| |||
669 | 671 | | |
670 | 672 | | |
671 | 673 | | |
| 674 | + | |
| 675 | + | |
672 | 676 | | |
673 | 677 | | |
674 | 678 | | |
| |||
788 | 792 | | |
789 | 793 | | |
790 | 794 | | |
| 795 | + | |
| 796 | + | |
791 | 797 | | |
792 | 798 | | |
793 | 799 | | |
| |||
1805 | 1811 | | |
1806 | 1812 | | |
1807 | 1813 | | |
1808 | | - | |
1809 | | - | |
1810 | | - | |
1811 | | - | |
1812 | | - | |
1813 | | - | |
1814 | | - | |
1815 | | - | |
1816 | | - | |
1817 | | - | |
1818 | | - | |
1819 | | - | |
1820 | | - | |
1821 | | - | |
1822 | | - | |
1823 | | - | |
1824 | | - | |
1825 | | - | |
1826 | | - | |
1827 | | - | |
1828 | | - | |
1829 | 1814 | | |
1830 | 1815 | | |
1831 | 1816 | | |
| |||
4944 | 4929 | | |
4945 | 4930 | | |
4946 | 4931 | | |
| 4932 | + | |
| 4933 | + | |
4947 | 4934 | | |
4948 | 4935 | | |
4949 | 4936 | | |
| |||
5001 | 4988 | | |
5002 | 4989 | | |
5003 | 4990 | | |
5004 | | - | |
| 4991 | + | |
5005 | 4992 | | |
5006 | 4993 | | |
5007 | 4994 | | |
| |||
5018 | 5005 | | |
5019 | 5006 | | |
5020 | 5007 | | |
| 5008 | + | |
| 5009 | + | |
5021 | 5010 | | |
5022 | 5011 | | |
5023 | 5012 | | |
| |||
7391 | 7380 | | |
7392 | 7381 | | |
7393 | 7382 | | |
| 7383 | + | |
| 7384 | + | |
| 7385 | + | |
| 7386 | + | |
| 7387 | + | |
| 7388 | + | |
| 7389 | + | |
| 7390 | + | |
| 7391 | + | |
| 7392 | + | |
| 7393 | + | |
| 7394 | + | |
| 7395 | + | |
| 7396 | + | |
| 7397 | + | |
| 7398 | + | |
| 7399 | + | |
7394 | 7400 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
850 | 852 | | |
851 | 853 | | |
852 | 854 | | |
853 | | - | |
| 855 | + | |
854 | 856 | | |
855 | 857 | | |
856 | 858 | | |
| |||
2429 | 2431 | | |
2430 | 2432 | | |
2431 | 2433 | | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
2432 | 2471 | | |
2433 | 2472 | | |
2434 | 2473 | | |
| |||
2879 | 2918 | | |
2880 | 2919 | | |
2881 | 2920 | | |
| 2921 | + | |
| 2922 | + | |
2882 | 2923 | | |
2883 | 2924 | | |
2884 | 2925 | | |
2885 | 2926 | | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
2886 | 2993 | | |
2887 | 2994 | | |
2888 | 2995 | | |
| |||
3657 | 3764 | | |
3658 | 3765 | | |
3659 | 3766 | | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
| 3793 | + | |
| 3794 | + | |
| 3795 | + | |
| 3796 | + | |
| 3797 | + | |
| 3798 | + | |
| 3799 | + | |
| 3800 | + | |
| 3801 | + | |
| 3802 | + | |
| 3803 | + | |
| 3804 | + | |
3660 | 3805 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1259 | 1259 | | |
1260 | 1260 | | |
1261 | 1261 | | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
1262 | 1312 | | |
1263 | 1313 | | |
1264 | 1314 | | |
| |||
0 commit comments