ワンクリックで
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;