-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGHttpsSvrPrj.dpr
More file actions
80 lines (67 loc) · 2.35 KB
/
GHttpsSvrPrj.dpr
File metadata and controls
80 lines (67 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
GHttpsSvrPrj - Simple HTTP Server Component
Author: Gecko71
Copyright: 2025
LICENSE:
========
This code is provided for non-commercial use only. The code is provided "as is"
without warranty of any kind, either expressed or implied, including but not
limited to the implied warranties of merchantability and fitness for a particular
purpose.
You are free to:
- Use this code for personal, educational, or non-commercial purposes
- Modify, adapt, or build upon this code as needed
- Share the code with others under the same license terms
You may not:
- Use this code for commercial purposes without explicit permission
- Remove this license notice from any copies or derivatives
THE AUTHOR(S) SHALL NOT BE LIABLE FOR ANY DAMAGES ARISING FROM THE USE
OF THIS SOFTWARE.
By using this code, you acknowledge that you have read and understood
this license and agree to its terms.
}
program GHttpsSvrPrj;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
GHTTPSServer in 'GHTTPSServer.pas',
GHTTPServer in 'GHTTPServer.pas',
HTTPRequest in 'HTTPRequest.pas',
HTTPResponseBuilder in 'HTTPResponseBuilder.pas',
HttpServerUtils in 'HttpServerUtils.pas',
Logger in 'Logger.pas',
OpenSSLWrapper in 'OpenSSLWrapper.pas',
GHTTPConstants in 'GHTTPConstants.pas';
var
Server: TGHTTPSServer;
HttpLogger: THttpLogger;
begin
HttpLogger := THttpLogger.Create();
try
HttpLogger.OnNewLogLineProc :=
procedure(Sender: TObject; const LogLine: string)
begin
WriteLn(LogLine);
end;
Server := TGHTTPSServer.Create(nil, 8443,200, HttpLogger);
try
Server.CertificatePath := 'cert.pem';
Server.PrivateKeyPath := 'key.pem';
Server.AddEndpointProc('/api/hello', 'GET',
procedure(Sender: TObject; ARequestParser: THTTPRequestParser;
AResponseBuilder: THTTPResponseBuilder; ASerwer: TGHTTPServer)
begin
AResponseBuilder.SetStatus(200, 'OK');
AResponseBuilder.AddTextContent('application/json', 'text/plain',
'{"message":"Hello from HTTPS server!"}');
end,atNone,[]);
// Uruchom serwer
Server.Start;
finally
Server.Free;
end;
finally
HttpLogger.free;
end;
end.