TsgcWebSocketServer_HTTPAPI › Events › OnHTTPRequest
Sunucu bir HTTP isteği aldığında tetiklenir, böylece uygulama yanıtı oluşturabilir.
property OnHTTPRequest: TsgcWSHTTPAPIRequestEvent;
// TsgcWSHTTPAPIRequestEvent = procedure(aConnection: TsgcWSConnection_HTTPAPI; const aRequestInfo: THttpServerRequest; var aResponseInfo: THttpServerResponse) of object
—
OnHTTPRequest, HTTP.SYS'in sunucuya ilettiği her HTTP isteği (GET, POST, PUT, DELETE, HEAD...) için ana giriş noktasıdır. aRequestInfo, çözülmüş isteği sunar (Document, Method, Headers, ContentType, Content, QueryParams, Cookies, ContentLength, AuthExists/AuthUsername/AuthPassword, Stream) ve aResponseInfo, uygulamanın geri göndermek istediği yanıtı toplar: gerektiğinde ResponseNo, ContentText (veya ikili/dosya yanıtları için ContentStream / FileName), ContentType, CustomHeaders, Date/Expires/LastModified ve CacheControl ayarlayın. Varsayılan HTTP 200'ü döndürmek için aResponseInfo'ya dokunmayın veya hata durumlarını bildirmek için ResponseNo'yu 404/500/... olarak atayın. Bu olay WebSocket yükseltme istekleri için tetiklenmez; bunlar bunun yerine OnConnect / OnHandshake aracılığıyla yönlendirilir.
procedure OnHTTPRequest(aConnection: TsgcWSConnection_HTTPAPI;
const aRequestInfo: THttpServerRequest;
var aResponseInfo: THttpServerResponse);
begin
if aRequestInfo.Method = 'GET' then
begin
if aRequestInfo.Document = '/test.html' then
begin
aResponseInfo.ResponseNo := 200;
aResponseInfo.ContentText := 'OK';
aResponseInfo.ContentType := 'text/html; charset=UTF-8';
end
else
aResponseInfo.ResponseNo := 404;
end
else
aResponseInfo.ResponseNo := 500;
end;