一键导入
horse-writing-middleware
Guide to writing custom middlewares for the Horse framework, following the callback flow with the Next parameter.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide to writing custom middlewares for the Horse framework, following the callback flow with the Next parameter.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Guidelines and workflows for developing and maintaining regular expressions and optional parameter routing features in the Horse framework.
Guidelines for registering, executing, and optimizing native high-precision telemetry hooks (AddOnTelemetry) in the Horse Web Framework.
Guidelines for instantiating and configuring independent Horse server instances (THorseInstance) running concurrently on different ports.
Guide for setting up thread-safe database connection pooling (FireDAC / UniDAC) in multithreaded Horse applications.
Guide for managing request-scoped contextual services and IoC (dependency injection) in Delphi and Lazarus.
Guide to using standard Horse middlewares (CORS, Jhonson, compression, basic-auth, logger) and pipeline registration order.
| name | horse-writing-middleware |
| description | Guide to writing custom middlewares for the Horse framework, following the callback flow with the Next parameter. |
A custom middleware is a procedure that receives THorseRequest, THorseResponse, and a callback procedure Next.
procedure MyCustomMiddleware(Req: THorseRequest; Res: THorseResponse; Next: TProc);
begin
// 1. Logic BEFORE the request reaches the endpoint handler
Req.Headers.AddOrSetValue('X-Processed-By', 'MyMiddleware');
// 2. Call Next to delegate execution to the subsequent middleware or route handler
Next;
// 3. Logic AFTER the route handler completes its execution
Res.Headers.AddOrSetValue('X-Execution-Finished', 'True');
end;
If a validation fails (e.g., authentication is missing), do NOT call Next. Set the status and send the response immediately. This halts the pipeline execution.
procedure AuthMiddleware(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
LToken: string;
begin
LToken := Req.Headers.Items['Authorization'];
if LToken.IsEmpty then
begin
// Halt execution by sending response and omitting the Next call
Res.Send('Unauthorized').Status(THTTPStatus.Unauthorized);
Exit;
end;
// Token is valid, proceed with pipeline
Next;
end;