Previously, when parsing INI configurations, `tun_fd` would default to `Some(-1)`. In [leaf/src/config/common.rs](cci:7://file:///Users/rikaaa0928/src/github/rust/leaf/leaf/src/config/common.rs:0:0-0:0), the logic checked `if let Some(fd) = ...`, which matched even for `-1`, causing the code to skip the `else` block.
This `else` block is critical as it contains the logic for applying `auto`, `name`, `address`, and other TUN settings. This commit changes the check to `if fd >= 0`, ensuring that if an invalid FD (like -1) is present, the code falls through to correctly configure the TUN interface using the provided parameters.
- Replace repetitive cache access code with unified priority-based approach
- Add config-driven cache query order (IPv6-first, IPv4-first, or IPv4-only)
- Extract common cache expiration check and IP extraction logic
- Improve code maintainability and eliminate duplication
- Maintain same functionality with cleaner architecture
No behavioral changes - only structural improvements.
Refactor the DNS lookup retry loop to reduce deeply nested `match` statements
and improve code clarity and maintainability.
The original implementation had multiple levels of nested `match` blocks
for handling send, receive, timeout, and DNS response parsing, which made
the logic hard to follow and error-prone.
This refactoring:
- Replaces deep nesting with early returns and `if let` bindings where appropriate.
- Keeps the existing error classification logic (e.g., which errors are retried
like timeouts or send failures, and which are fatal like parse errors or
invalid DNS responses).
- Improves readability by organizing the steps sequentially:
send → receive (with timeout) → parse → validate → extract IPs → build result.
- Maintains all existing behavior including retry logic and error handling.
- Adds clarity around TTL extraction and deadline calculation.
No functional changes — only structural and readability improvements.
When forwarding HTTP/1.x absolute-form requests from the HTTP inbound, we
serialize a new request line/headers and then append the buffered remainder.
However, the remainder starts at the original End-Of-Headers (EOH, CRLFCRLF),
so we ended up emitting two consecutive CRLFCRLF boundaries. That breaks
parsing for some servers, especially with chunked bodies or JSON payloads.
Strip a leading EOH from the remainder before concatenation so only one header
terminator is present.
This change is minimal and only affects the Absolute target format path. CONNECT
and SOCKS remain pure tunnels.