TsgcWebSocketHTTPServer | 404 Error without Response Body

By default, the Indy library adds a content body to HTTP responses if there is no ContentText or ContentStream assigned. If you want to return an empty response body (for a 404 error or similar), you can use the following approach.

 

Create a new TStringStream without content and assign it to the ContentStream property of the HTTP Response. This way the HTTP response will be sent without the default HTML tags.

 

Example

 


procedure OnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; 
  AResponseInfo: TIdHTTPResponseInfo);
begin
  AResponseInfo.ContentStream := TStringStream.Create('');
  AResponseInfo.ContentType := 'text/html';
  AResponseInfo.ResponseNo := 404;
end;