TsgcWebSocketHTTPServer › イベント › OnCommandGet
HTTPサーバーがGET、POST、またはHEADリクエストを受信したときに発生し、アプリケーションがレスポンスを構築できるようにします。
property OnCommandGet: TIdHTTPCommandEvent;
// TIdHTTPCommandEvent = procedure(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo) of object
—
OnCommandGetは、コンポーネントが処理するHTTPトラフィック(GET、POST、HEAD)の主要なエントリポイントです。ARequestInfoはリクエスト(Document、Params、AuthUsername、Headers、PostStream、RemoteIPなど)を公開し、AResponseInfoは送信レスポンスです: ContentTextまたはContentStreamにボディを、ContentTypeにMIMEタイプを、ResponseNoにHTTPステータスコード(200、404など)を設定します。AResponseInfo.ServeFileを呼び出すと、ディスクからファイルをディスパッチします。ハンドラーは接続スレッドのコンテキストで実行されるため、直接のUIアクセスは避けるか、同期ディスパッチに切り替えてください。既にDocumentRoot配下にあるファイルへのリクエストは自動的に処理され、このイベントはトリガーされません。
procedure OnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
begin
if ARequestInfo.Document = '/' then
begin
AResponseInfo.ContentText := '<html><head><title>Test Page</title></head><body></body></html>';
AResponseInfo.ContentType := 'text/html';
AResponseInfo.ResponseNo := 200;
end;
end;