plugins/litestar/skills/litestar-middleware/SKILL.md
Design and apply Litestar middleware for cross-cutting concerns such as CORS, CSRF, allowed-host checks, compression, rate limiting, logging, sessions, request enrichment, policy enforcement, and custom ASGI pipeline control. Use when behavior must wrap broad route sets consistently across the ASGI stack. Do not use for route-specific business rules, simple response mutation better handled by lifecycle hooks, or auth/guard policy work that belongs in security-focused skills.
npx skillsauth add alti3/litestar-skills litestar-middlewareInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
http, websocket, and lifespan as needed.404 and 405 expectations explicit because those router-generated exceptions occur before the middleware stack.ASGIMiddleware for configurable production custom middleware.MiddlewareProtocol for minimal low-level behavior.AbstractMiddleware only for compatibility or migration scenarios.DefineMiddleware when constructor-style args must be supplied to a middleware factory or class.litestar-lifecycle-hooks instead when the behavior belongs to after_request, before_send, or related hook stages.Read only the sections you need:
ASGIMiddleware, MiddlewareProtocol, AbstractMiddleware, and DefineMiddleware, read references/custom-middleware-patterns.md.opt-based skips narrow and tested.404 and 405 pass through middleware.opt exclusions or path patterns.exclude_opt_key, or scopes behave as intended.404 and 405 behavior is handled at the right boundary.litestar-lifecycle-hooks for hook-stage logic rather than raw ASGI wrapping.litestar-authentication, litestar-security, litestar-logging, and litestar-metrics for domain-specific middleware outcomes.litestar-debugging when middleware interactions are the source of a runtime defect.litestar-routing when middleware behavior depends on layer placement or opt strategy.development
Build Litestar WebSocket endpoints with low-level websocket handlers, websocket listeners, websocket streams, dependency injection, custom websocket classes, transport-mode control, and graceful connection lifecycle handling. Use when implementing bidirectional real-time communication, reactive websocket message handling, or proactive server push over WebSockets. Do not use for server-side pub/sub fanout that is better expressed with channels alone.
tools
Test Litestar applications with TestClient, AsyncTestClient, create_test_client, websocket test helpers, dependency overrides, mocked dependencies, lifecycle-aware fixtures, and deterministic success and failure assertions. Use when adding or fixing Litestar test coverage, including exception contracts, override precedence, websocket behavior, event-bus side effects, or live-server-only response patterns. Do not use as a substitute for production observability or runtime debugging strategy.
development
Configure Litestar templating with `TemplateConfig`, Jinja/Mako/MiniJinja engines, file-or-string `Template` responses, request and CSRF-aware context, template callables, and custom engine integration. Use when implementing or fixing server-rendered HTML in Litestar. Do not use for static asset serving or pure JSON API endpoints.
development
Configure Litestar stores and the store registry for caching, server-side sessions, rate limiting, and other key-value state with explicit backend selection, bytes-safe data handling, TTL and renewal policy, namespacing, registry wiring, and lifecycle cleanup. Use when a Litestar app depends on `MemoryStore`, `FileStore`, `RedisStore`, `ValkeyStore`, or `StoreRegistry`. Do not use for relational persistence, domain repositories, or response-caching policy details that belong in database or caching-focused skills.