this.env
Light‑weight environment recognition & trust middleware for Rust. It provides a simple, extensible way to determine the origin of requests and their trustworthiness, allowing your application to make informed decisions about how to handle them.
Goal: Let your application decide and learn where it is running (localhost, extensions, remote web, CLI, …) and how much it should trust that origin – before you execute business‑logic.
🛠️ Main Rust API
| Call | What it gives you |
|---|---|
Env::resolve(&EnvRequest) |
Returns EnvStatus (Approved, PendingApproval, Blocked). |
Env::status(&self, db) |
Re‑evaluate status for an existing Env. |
Env::add_endorsement(db, e) |
Add / change a user decision. |
Env::get_endorsements(db, domain) |
List all recorded decisions. |
Env::is_endorsed_by(db, domain, who) |
true / false. |
All data lives in a single .db file next to your executable. No server, no migrations.
🧠 MIDDLEWARE
A smart middleware system that inspects incoming HTTP requests and evaluates their environment (origin, IP, headers, cookies, etc.) to determine whether the request should be Approved, Blocked, or Pending Approval. It is ideal for building decentralized permission systems and real-time trust evaluation.
- Recibe EnvRequest
- Busca identidad → log
- Si no hay identidad → PendingApproval
- Si hay identidad: a. Instancia Env → log b. ¿Endorsed? - Sí → Approved - No → PendingApproval
- ¿Blocked por alguna regla? → Blocked
EnvResquestInfo - information about the request, such as method, path, host, timestamp, etc. EnvRequestLog - a log entry for a request, including method, path, host, timestamp, and status as minimal data.
🚀 Quick start (Actix Web)
use actixMiddleware; // import
// Inside your Actix `App` builder
new
.wrap // 1‑line, sensible defaults
.configure;
Add Port Number to the Middleware.
### Custom rules
use ;
let cfg = ActixMwConfig ;
new
.wrap
.configure;
This file defines a status handler using this.env. It responds to HTTP GET requests at the /status endpoint with the current environment status. It uses the this.env crate to read the environment status stored by the middleware. The response includes the status, port, and username in JSON format.
use ;
use EnvStatus;
use json;
async
🧐 What it does
- Sees every inbound request (HTTP, WebSocket, CLI …).
- Figures out its “environment” (localhost, remote site, browser extension …).
- Checks a tiny SQLite registry to know if that environment is:
Approved– trusted, go ahead.PendingApproval– first time seen, ask the user.Blocked– explicitly forbidden.
- Returns the decision before your business‑logic runs.
📦 Key Components
- Env Represents the interpreted request “environment” extracted from an incoming Actix HttpRequest. Usage:
let env_request = from_request;
This attempts to extract identifying info (e.g., origin, IP, etc.) into an evaluable context.
- EnvStatus An enum returned by Env::resolve that represents the outcome of evaluating a request environment. Variants:
• Approved: The request is trusted and allowed to proceed. • PendingApproval(data): The request is not yet decided; it awaits user confirmation or other logic. • Blocked(reason): The request is explicitly denied, with an optional reason string.
Usage:
let status = match env_request ;
✅ Status Response Integration
You can use this logic to return a JSON response in your Actix handler:
let status_str = match resolved_status ;
Ok.json;
Maintained by neurons.me — crafted with ☕ by suiGn.