Introducing a new way to review your PRs.

Read the announcement

hcavarsan / kftray

kubectl port-forward manager and reverse tunnel (ngrok-like) for exposing local services publicly, with TLS termination, HTTP traffic inspection, UDP forwarding, multi-hop proxy routing through k8s clusters, stateful config via filesystem or git - GUI and TUI available

View on GitHub

19 documents · Updated Nov 23, 2026

docs / http-logging-and-network-monitoring

HTTP logging and network monitoring

HTTP logging records request and response exchanges for a port forward so an engineer can inspect traffic after it passes through the forward. Network monitoring watches basic connectivity and the health of active forwards, then restores failed forwards when the network returns. HTTP data is kept in per-forward .http files, while monitor state is shown through the desktop settings UI rather than a separate event log.

This page complements observability and user controls. For related user-facing behavior, see desktop frontend, configuration workflows, and telemetry and shortcuts.

System boundary

HTTP capture

The HTTP log crate turns raw HTTP traffic into readable request and response records. It links each response to its request with a trace ID and records the response time. The capture is enabled per port-forward configuration, so unrelated forwards do not share one traffic record.

The capture handles normal, chunked, compressed, streaming, and WebSocket upgrade responses. It uses protocol evidence before it marks a response complete, then formats readable text bodies and marks binary or incomplete content instead of treating it as ordinary text. Long or open-ended streams can produce a bounded record before the connection ends.

References: crates/…/http_request_handler.rs• L20-53 crates/…/http_response_handler.rs• L153-245 crates/…/http_response_handler.rs• L251-334 crates/…/http_response_analyzer.rs• L155-249

Network recovery

The network-monitor crate protects active port forwards from changes outside the forward itself. It checks whether at least one known network endpoint is reachable, checks the local listener for each active forward, and restarts forwards after a stable network recovery or a confirmed health failure.

The monitor has a main loop for state changes and health work plus a background loop for network changes and scheduled checks. These loops share task state so a reconnect or health check runs once even when both loops observe the same condition. The main visible results are the running or stopped status in Settings and the restored or still-failed port-forward rows. The monitor does not restart forwards that are no longer registered as running or that are already in their own recovery flow.

References: crates/…/network.rs• L9-98 crates/…/health.rs• L77-179 crates/…/monitor.rs• L61-219 crates/…/config_manager.rs• L16-39 crates/…/config_manager.rs• L82-180

HTTP log data

Request and response records

Each HTTP file contains a readable sequence of request and response records. A record includes a trace ID, a timestamp, the HTTP line, headers, and a body when the body can be shown. Response records also include the time taken in milliseconds.

The formatter presents JSON in an indented form and labels binary, empty, unknown, or truncated bodies. It removes transfer chunks and tries to decode common content encodings before formatting the body. This makes the file useful for diagnosis without requiring the reader to reconstruct transport framing by hand.

References: crates/…/message.rs• L9-30 crates/…/formatter.rs• L30-87 crates/…/parser.rs• L462-583 crates/…/parser.rs• L821-1041

Capture lifecycle

When an enabled forward receives a request, the logger writes the request and saves its trace ID. As response data arrives, the response handler gathers it until protocol evidence or a safe stream limit allows logging. The logger then pairs the response with the saved request and appends both records to that forward’s file.

The flow is:

flowchart LR
    A[Raw request] --> B{HTTP logs enabled?}
    B -- No --> C[Forward traffic only]
    B -- Yes --> D[Create trace ID and write request]
    D --> E[Gather response data]
    E --> F{Complete or safe to flush?}
    F -- No --> E
    F -- Yes --> G[Format response and duration]
    G --> H[Append to per-forward .http file]

The response analyzer uses content length, chunk end markers, no-body status codes, connection close, and a valid WebSocket handshake as completion signals. It checks chunk markers in the response body rather than unrelated header values. Long-lived or large streams can be logged as a bounded snapshot, and remaining data is handled when the connection closes.

References: crates/…/http_request_handler.rs• L20-43 crates/…/http_response_handler.rs• L153-249 crates/…/http_response_handler.rs• L251-334 crates/…/http_response_handler.rs• L545-623 crates/…/http_response_analyzer.rs• L72-168

File lifecycle

The logger creates one active file for a configuration ID and local port. It uses the .http suffix and rotates the active file before a new record would exceed its configured size. Rotated names use a timestamp with a numeric suffix when needed, and automatic cleanup removes only matching rotated files older than the retention period. The default file limit is 10 MB and the default retention period is 7 days.

HTTP log files are separate from the application log files used by the desktop Log Viewer. This distinction matters when diagnosing a report: the viewer shows application events, while an HTTP exchange is opened from the port-forward actions or from the HTTP log controls.

References: crates/…/config.rs• L17-21 crates/…/config.rs• L71-179 crates/…/logger.rs• L276-285 crates/…/logger.rs• L432-504 crates/…/httplogs.rs• L203-227

User controls

Per-forward HTTP controls

Each port-forward row can enable or disable HTTP capture, open its matching .http file, and open a configuration dialog. The dialog saves the capture flag, the maximum file size, the retention period, and automatic cleanup for that configuration.

The settings are stored by configuration ID. If a setting is missing, capture is off and the default file and retention values apply. The same values are also kept with the exported configuration data so an import or edit can preserve the user’s HTTP logging choice.

References: frontend/…/index.tsx• L96-110 frontend/…/index.tsx• L333-373 frontend/…/index.tsx• L67-163 crates/…/http_logs_config_model.rs• L6-49 crates/…/http_logs_config.rs• L66-117

Desktop application log viewer

The desktop Log Viewer is a separate view for the application’s own log files. It lists current and rotated application files, reads the latest entries, and parses standard timestamp, level, module, and message fields when the line has the expected format. Lines that do not match remain visible as raw entries.

The viewer supports file selection, search, level and module filters, copy, clear, delete of rotated files, opening the log folder, diagnostic export, and follow mode for the current file. It does not parse HTTP .http files as viewer entries. Use the per-forward inspect action or the HTTP log file controls to read HTTP traffic.

References: crates/…/logs.rs• L31-71 crates/…/logs.rs• L224-338 frontend/…/LogViewerPage.tsx• L39-80 frontend/…/LogFileSelector.tsx• L23-65 frontend/…/LogViewerToolbar.tsx• L78-223

HTTP log configuration

The HTTP log dialog is the main control surface for traffic capture. It shows the stored values for one forward and validates the file limit from 1 to 100 MB and the retention period from 1 to 365 days before saving.

The dialog can also prune all HTTP files. This action applies to every configuration, not only the forward whose dialog is open. The Settings page has a different log-retention card for application logs and a button that opens the desktop Log Viewer, so the two controls should not be treated as one retention policy.

References: frontend/…/index.tsx• L125-163 frontend/…/index.tsx• L165-184 frontend/…/index.tsx• L260-309 frontend/…/LogSettings.tsx• L29-134

Network monitor settings

The Settings page exposes one network-monitor switch and a status label. Saving the switch persists the preference and starts, restarts, or stops the monitor so the displayed state follows the requested mode.

The monitor starts with the desktop application when the saved preference is enabled. It can also run with the terminal UI. Its work is silent unless a forward changes state or a restart fails, so the switch and the port-forward status are the main user-facing results.

References: frontend/…/NetworkSettings.tsx• L9-64 frontend/…/useSettingsSave.ts• L125-145 crates/…/settings.rs• L59-70 crates/…/settings.rs• L153-175 crates/…/lib.rs• L23-45

Network monitor flow

Connectivity and health checks

The monitor runs two related checks. Connectivity checks ask whether the host can reach at least one probe endpoint. Health checks ask whether each active forward still has a usable local listener. The main and background loops share a task state that prevents duplicate reconnect and health work, while the monitor skips idle work when there are no active forwards.

When the network changes from down to up, the monitor waits for a stable period and rate-limits reconnect attempts. The background loop also records network interface changes without treating them as proof that forwards must restart. When a health check finds a failed forward, it confirms the failure before asking the configuration manager to restart it. A fast health check can run after a network failure and releases its shared health-check slot when it ends.

References: crates/…/types.rs• L34-83 crates/…/monitor.rs• L87-219 crates/…/monitor.rs• L256-329

Forward restart boundary

The monitor only acts on forwards that are active in the selected database mode and still registered in the current process. Before a restart, it checks that the user did not stop the forward and leaves forwards with an active recovery manager alone. Direct forwards and relay-based forwards use their matching start path after the stop step.

This boundary is important for user control. A network outage can cause automatic recovery, but a user stop or a forward-owned recovery action takes precedence over the monitor.

References: crates/…/config_manager.rs• L16-39 crates/…/config_manager.rs• L82-180 crates/…/types.rs• L87-130

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the per-forward HTTP setting aligned across HttpLogsConfig, its database record, the Tauri commands, and the port-forward row query keys.
  • Keep .http active and rotated file naming aligned with rotation matching, file-opening, cleanup, and prune commands.
  • If HTTP record formatting changes, check both normal response capture and preformatted response capture because both write to the same file format.
  • If response completion rules change, keep the analyzer and response handler aligned for content length, chunk markers, WebSocket handshakes, stream limits, and connection-close data.
  • If monitor start or stop behavior changes, keep the saved network_monitor preference and the reported network_monitor_status state consistent.
  • If response completion rules change, preserve the link between the request trace ID and the response request ID.
  • If monitor scheduling changes, keep the main and background loops aligned with the shared task state so one network event cannot start duplicate recovery work.

Important failure modes

TriggerConsequenceGuard
HTTP logging is disabled or its setting cannot be readTraffic passes without an HTTP recordThe request and response handlers treat a missing setting as disabled and the UI shows the per-forward switch.
A chunk terminator-like value appears in headers or a WebSocket response lacks a valid handshakeThe response can be logged too early or remain pendingChunk scanning starts at the body and WebSocket completion requires the expected upgrade response and handshake headers.
Response data never reaches a recognized completion stateThe response can remain buffered and is not written at the normal completion pointCompletion checks cover content length, chunk termination, no-body responses, connection close, WebSocket upgrades, and bounded long streams.
A new record would exceed the active file limitThe active file can grow beyond the configured sizeThe logger rotates before writing the record and uses a unique rotated path.
An HTTP body exceeds the configured or safe decoded sizeThe log does not contain the full bodyThe formatter marks content as too large or truncated instead of expanding it without bound.
The network is unstable or reconnect attempts reach the limitActive forwards remain down until a later permitted recoveryThe monitor requires stable connectivity, rate-limits attempts, and caps reconnect attempts.
Both monitor loops observe the same recovery or health eventDuplicate recovery work can race or overload a forwardShared task state allows only one reconnect or health check at a time.
A user stops a forward while a restart is pendingAn automatic restart could undo the user actionThe restart path checks process registration and stop generations before starting the forward.
A current application log file is selected for deletionThe active logger could keep writing to an unlisted fileThe application log commands allow clearing the current file but reject deleting it.

Key files

FileWhy to read it
crates/…/logger.rsMain HTTP record lifecycle, trace pairing, file writing, rotation, policy updates, and shutdown.
crates/…/http_response_handler.rsResponse buffering, completion decisions, stream fallbacks, and the point where a response becomes a log record.
crates/…/http_response_analyzer.rsProtocol signals used to decide whether response data is complete.
crates/…/config.rsHTTP log defaults, file naming, rotation names, and retention matching.
crates/…/formatter.rsThe shape and readability rules for request, response, and body content.
crates/…/http_logs_config_model.rsThe user-facing HTTP logging settings and defaults.
crates/…/httplogs.rsDesktop commands for HTTP settings, file size, pruning, and opening an HTTP file.
crates/…/logs.rsDesktop application log discovery, parsing, retention, and viewer data commands.
frontend/…/LogViewerPage.tsxThe desktop application log viewer flow and its available actions.
frontend/…/index.tsxPer-forward HTTP logging controls and validation.
crates/…/monitor.rsConnectivity, shared scheduling state, health checks, recovery, and restart coordination.
crates/…/config_manager.rsThe safety boundary between monitor decisions and forward restarts.
frontend/…/NetworkSettings.tsxThe network-monitor setting and running-state display.