2017-11-23 17:29:51 +01:00
|
|
|
program OutputCompressionSample;
|
|
|
|
|
2017-12-12 18:32:41 +01:00
|
|
|
{$APPTYPE CONSOLE}
|
2017-11-23 17:29:51 +01:00
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
MVCFramework.Logger,
|
|
|
|
MVCFramework.Commons,
|
|
|
|
MVCFramework.REPLCommandsHandlerU,
|
|
|
|
Web.ReqMulti,
|
|
|
|
Web.WebReq,
|
|
|
|
Web.WebBroker,
|
|
|
|
IdHTTPWebBrokerBridge,
|
|
|
|
MainControllerU in 'MainControllerU.pas',
|
2018-10-23 16:18:34 +02:00
|
|
|
WebModuleU in 'WebModuleU.pas' {MyWebModule: TWebModule},
|
2017-11-23 17:29:51 +01:00
|
|
|
InMemoryDataU in '..\renders\InMemoryDataU.pas',
|
2018-10-23 16:18:34 +02:00
|
|
|
BusinessObjectsU in '..\commons\BusinessObjectsU.pas',
|
|
|
|
RandomUtilsU in '..\commons\RandomUtilsU.pas';
|
2017-11-23 17:29:51 +01:00
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
|
|
|
procedure RunServer(APort: Integer);
|
|
|
|
var
|
|
|
|
lServer: TIdHTTPWebBrokerBridge;
|
|
|
|
lCustomHandler: TMVCCustomREPLCommandsHandler;
|
|
|
|
lCmd: string;
|
|
|
|
begin
|
|
|
|
Writeln('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION);
|
|
|
|
if ParamCount >= 1 then
|
|
|
|
lCmd := ParamStr(1)
|
|
|
|
else
|
|
|
|
lCmd := 'start';
|
|
|
|
|
2017-12-12 18:32:41 +01:00
|
|
|
lCustomHandler := function(const Value: string; const Server: TIdHTTPWebBrokerBridge; out Handled: Boolean): THandleCommandResult
|
2017-11-23 17:29:51 +01:00
|
|
|
begin
|
|
|
|
Handled := False;
|
|
|
|
Result := THandleCommandResult.Unknown;
|
|
|
|
|
|
|
|
// Write here your custom command for the REPL using the following form...
|
|
|
|
// ***
|
|
|
|
// Handled := False;
|
|
|
|
// if (Value = 'apiversion') then
|
|
|
|
// begin
|
|
|
|
// REPLEmit('Print my API version number');
|
|
|
|
// Result := THandleCommandResult.Continue;
|
|
|
|
// Handled := True;
|
|
|
|
// end
|
|
|
|
// else if (Value = 'datetime') then
|
|
|
|
// begin
|
|
|
|
// REPLEmit(DateTimeToStr(Now));
|
|
|
|
// Result := THandleCommandResult.Continue;
|
|
|
|
// Handled := True;
|
|
|
|
// end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
try
|
|
|
|
LServer.DefaultPort := APort;
|
|
|
|
|
|
|
|
{ more info about MaxConnections
|
|
|
|
http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=TIdCustomTCPServer_MaxConnections.html }
|
|
|
|
LServer.MaxConnections := 0;
|
|
|
|
|
|
|
|
{ more info about ListenQueue
|
|
|
|
http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=TIdCustomTCPServer_ListenQueue.html }
|
|
|
|
LServer.ListenQueue := 200;
|
|
|
|
|
2017-12-12 18:32:41 +01:00
|
|
|
{ ************* }
|
|
|
|
WriteLn('To test the compression middleware call the following URL:');
|
|
|
|
WriteLn(' http://localhost:8080/customers (compression enabled)');
|
|
|
|
WriteLn(' http://localhost:8080/tallcustomers (compression disable because response length < 1024 bytes)');
|
|
|
|
{ ************* }
|
|
|
|
|
2017-11-23 17:29:51 +01:00
|
|
|
WriteLn('Write "quit" or "exit" to shutdown the server');
|
|
|
|
repeat
|
|
|
|
if lCmd.IsEmpty then
|
|
|
|
begin
|
2017-12-12 18:32:41 +01:00
|
|
|
write('-> ');
|
2017-11-23 17:29:51 +01:00
|
|
|
ReadLn(lCmd)
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
case HandleCommand(lCmd.ToLower, LServer, lCustomHandler) of
|
|
|
|
THandleCommandResult.Continue:
|
|
|
|
begin
|
|
|
|
Continue;
|
|
|
|
end;
|
|
|
|
THandleCommandResult.Break:
|
|
|
|
begin
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
THandleCommandResult.Unknown:
|
|
|
|
begin
|
|
|
|
REPLEmit('Unknown command: ' + lCmd);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
lCmd := '';
|
|
|
|
end;
|
|
|
|
until false;
|
|
|
|
|
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
ReportMemoryLeaksOnShutdown := True;
|
|
|
|
IsMultiThread := True;
|
|
|
|
try
|
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
|
|
|
WebRequestHandlerProc.MaxConnections := 1024;
|
|
|
|
RunServer(8080);
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
Writeln(E.ClassName, ': ', E.Message);
|
|
|
|
end;
|
2017-12-12 18:32:41 +01:00
|
|
|
|
2017-11-23 17:29:51 +01:00
|
|
|
end.
|