Laravel Rust✓ Human-reviewed

Informational browser and OS labels in Laravel Rust

Replace display-only Agent browser/platform calls with an app-owned Woothee projection; make unknown values, borrowed lifetimes and deliberate parser differences explicit.

Approved 2026-12-04T13:20:40.216441Z · Submission 51

Informational browser and OS labels in Laravel Rust

Scope and attribution

Replace only Agent browser/platform labels used for display, not the full detection API. Own the projection in the application while retaining an established parser and its rule data. Compare the package and framework refs in this recipe's metadata with the destination application's lockfile before choosing dependency versions.

Dependency source checked on 2026-12-04: woothee/woothee-rust, commit 9ebc35bbadadfbdc18f1eba911d0d28d382dd176 (source manifest version 0.13.0). Inspect src/parser.rs and the bundled generated dataset. This is a research baseline, not a request to upgrade blindly.

Inspect Agent's src/Agent.php, src/AgentServiceProvider.php, tests/AgentTest.php and composer.json. Agent is MIT licensed; retain its notice if adapting source or fixtures. The proposed Woothee Rust parser is Apache-2.0 licensed; retain its applicable notices and data attribution. No target-application conversion or compatibility trial has been performed with this guidance.

At the time of writing, the Package Port catalog listed a community Rust equivalent at mischasigtermans/laravel-user-agent-rust, explicitly not a direct port; check get-recipe's current port catalog. Evaluate it first if broader coverage matters. The inline path here is a deliberately smaller browser/OS display summary.

Source behavior and deliberate differences

If the installed Agent uses the inspected rule tables, browser lookup checks specific Edge/Opera tokens before generic Chrome, merges platform rules with Mobile Detect, and returns PHP false when unmatched. Mobile/tablet and crawler predicates come from separate engines. deviceType() is not equivalent to a single generic parser category.

Woothee names and precedence differ from Agent. Its result contains name, os, category and version fields; UNKNOWN fields or no result mean unknown, not desktop. This recipe does not promise Agent-compatible names, device categories, version extraction, language negotiation or crawler detection. Preserve old persisted labels, or explicitly version their analytics interpretation rather than rewriting history.

Adapt the request consumer

  1. Find every facade/service/Blade/directive caller and identify the output actually consumed. Do not remove Agent until callers needing excluded functionality have another reviewed implementation.
  2. Add the Woothee dependency using the inspected revision or a release whose source/API you have reconciled with the research baseline. Commit the destination Cargo.lock. Keep built-in rules pinned; do not download mutable rule data on request paths.
  3. Read request.header("user-agent"). Missing, whitespace-only, invalid-text or over-4096-byte input maps to unknown labels before parsing. The byte cap is application policy; retain the HTTP server's header-size limits too. With the inspected Parser::parse API, the owned projection is:
let parser = woothee::parser::Parser::new();
let parsed = parser.parse(ua);
let browser = parsed.as_ref()
    .filter(|p| !p.name.is_empty() && p.name != "UNKNOWN")
    .map(|p| p.name.to_owned());
let platform = parsed.as_ref()
    .filter(|p| !p.os.is_empty() && p.os != "UNKNOWN")
    .map(|p| p.os.to_owned());

This fragment assumes ua has passed the input checks. Return Option<String> values through the existing response DTO, serializing unknowns as null. Result strings can borrow the input; copy only the two fields if the result outlives the handler's header borrow. Never put borrowed request data in process-global state.

  1. Keep all parsing results request-local. A reusable immutable parser is acceptable if the installed type's thread-safety contract allows it; do not introduce a mutable shared current-user-agent service.
  2. Keep names informational. User-Agent is caller-controlled and is not identity, authentication, reliable bot evidence or proof of feature support. Render with escaping/JSON serialization. Do not store raw headers unless an explicit privacy/retention policy requires it.
  3. Avoid public caching of variant output until its cache key is reviewed. Raw User-Agent cache keys have unbounded cardinality; a finite explicit display variant or private response is safer.

Acceptance trial

Use attributed Agent fixtures to discover differences, not to assume identical results from a different engine. Run an Edge string containing Chrome/ and Edg/, Opera containing OPR/, Safari, iPhone Safari, Android Chrome, and a bot. Approve expected browser and OS labels separately. Unknown results are allowed only where the new application contract explicitly permits them.

  • Missing, blank, malformed and arbitrary UAs produce null labels, never implied desktop/human trust.
  • Values at and beyond the configured byte cap exercise the intended boundary; invalid header encoding does not panic.
  • HTML-looking labels/headers are escaped. No header content influences a query identifier or authorization decision.
  • Concurrent requests with unrelated UAs retain their own labels. Existing login and feature-gate behavior remains independent of the summary.
  • No excluded Agent caller remains before removing the dependency.

Run cargo fmt --check, the target application's cargo test, and its strict Clippy checks. Record Rust/framework/parser and rule-data versions, commands, fixture output and intentional compatibility differences with the change.