{$mode objfpc}
program server;

uses
	sysutils,
	strutils,
	opensslsockets,
	classes,
	fphttpserver;
	
	
type
	meHTTPServer = class( TFPHTTPServer )		
		procedure handleRequest( var aRequest: TFPHTTPConnectionRequest; var aResponse : TFPHTTPConnectionResponse ); override;
	end;

	
var
	serv 		: meHTTPServer;


procedure meHTTPServer.handleRequest( var aRequest: TFPHTTPConnectionRequest; var aResponse: TFPHTTPConnectionResponse );
begin
	writeln( 'Incoming request' );
	if( aRequest.contentLength > 0 ) then
	begin	
		writeln( 'I HAVE CONTENT' );
		writeln( aRequest.content );
	end;
	
	aResponse.content := 'OK';
end;


begin
	writeln( 'Starting...' );
	serv := meHTTPServer.create( nil );
	serv.port := 8889;
	
	try
		writeln( 'READY' );
		serv.active := true;
	except
		on e : exception do 
		begin
			writeln( e.message );
			halt( 0 );
		end;
	end;
end.