Skip to content

Commit

Permalink
add SSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
DmBel committed Jul 9, 2023
1 parent 420c4a3 commit 992705f
Show file tree
Hide file tree
Showing 10 changed files with 2,094 additions and 31 deletions.
11 changes: 8 additions & 3 deletions Project2.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<MainSource>Project2.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<Platform Condition="'$(Platform)'==''">Win64</Platform>
<TargetedPlatforms>3</TargetedPlatforms>
<AppType>Application</AppType>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
Expand Down Expand Up @@ -60,6 +60,11 @@
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<DCC_UsePackage>vquery200;IndyProtocols200;pgprovider200;FireDACSqliteDriver;DBXSqliteDriver;FireDACPgDriver;accessprovider200;fmx;uniGUI20Core;TeeDB;tethering;vclib;DBXInterBaseDriver;mongoprovider200;DbxCommonDriver;crcontrols200;vclimg;dbxcds;IndySystem200;dbfprovider200;tdsprovider200;vcldb;vcldsnap;liteprovider200;uniGUI20VCL;odbcprovider200;fmxFireDAC;dacvcl200;CustomIPTransport;JvCore;RVDBPkgDXE6;vclribbon;adsprovider200;dsnap;fmxase;vcl;dacfmx200;oraprovider200;CloudService;FmxTeeUI;FireDACIBDriver;soapserver;inetdbxpress;dsnapxml;uSynEdit_R2016;adortl;FireDACASADriver;aseprovider200;AviPack;uniTools20;bindcompfmx;FireDACODBCDriver;RESTBackendComponents;rtl;dbrtl;DbxClientDriver;DSPack_DXE2;FireDACCommon;bindcomp;inetdb;IndyCore200;dac200;uniGUI20;Tee;vclFireDAC;xmlrtl;ibxpress;uniGUI20m;DBXMySQLDriver;FireDACCommonDriver;bindcompdbx;soaprtl;bindengine;vclactnband;FMXTee;TeeUI;bindcompvcl;ibprovider200;db2provider200;unidacvcl200;vclie;unidacfmx200;FireDACADSDriver;vcltouch;unidac200;myprovider200;PngComponents;uIndy20;VclSmp;FireDAC;VCLRESTComponents;CoolTrayIconD16;Intraweb;dsnapcon;uniGUI20Chart;inet;fmxobj;FireDACMySQLDriver;soapmidas;vclx;fmxdae;RESTComponents;FireDACMSAccDriver;dbexpress;SpTBXLib;JvBDE;$(DCC_UsePackage)</DCC_UsePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
Expand Down Expand Up @@ -111,7 +116,7 @@
<Deployment/>
<Platforms>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
<Platform value="Win64">True</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
Expand Down
Binary file modified Project2.res
Binary file not shown.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# SynHTTP
The synapse HTTP(s) Server, compitible wtih Delphi and FPC, Windows and Linux. Production ready

How to test it. Compile demo app, strart, puch a button. The Server should start on the 8080 port.
Type in the any browser: http://127.0.0.1:8080/?Ping=Ping
The server should answer: Pong
Also you could enable SSL mode and open client with https protocol:
https://127.0.0.1:8080/?Ping=Ping
2 changes: 1 addition & 1 deletion SynSrv.pas
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TSynTcpSrvConnection = class(TThread)
TCommandHandler = procedure(Connection: TSynTcpSrvConnection; Command: string) of object;

// TSynTcpServer - Generic TCP server component
[ComponentPlatformsAttribute(pidAllPlatforms)]
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
TSynTcpServer = class(TComponent)
protected
FActive: boolean;
Expand Down
15 changes: 12 additions & 3 deletions Unit2.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ object Form2: TForm2
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 208
Top = 96
Left = 16
Top = 56
Width = 75
Height = 25
Caption = 'Button1'
Caption = 'Start server'
TabOrder = 0
OnClick = Button1Click
end
object CheckBox1: TCheckBox
Left = 16
Top = 24
Width = 97
Height = 17
Caption = 'Enable SSL mode'
TabOrder = 1
OnClick = CheckBox1Click
end
end
35 changes: 32 additions & 3 deletions Unit2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, SynHttpSrv, Vcl.StdCtrls, SynSrv;
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
SynHttpSrv,
ssl_openssl_lib,
ssl_openssl,
Vcl.StdCtrls,
SynSrv;

type
TForm2 = class(TForm)
Button1: TButton;
Button1: TButton;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
private
FSynHttpServer: TSynHttpServer;
{ Private declarations }
Expand Down Expand Up @@ -49,7 +63,22 @@ procedure TForm2.Button1Click(Sender: TObject);
FSynHttpServer := TSynHttpServer.Create(Self);
FSynHttpServer.OnHttpGet := SynHttpServer1HttpGet;
FSynHttpServer.Port := '8080';
FSynHttpServer.HTTPSEnabled := CheckBox1.Checked;
TryToOpenWebPort;
if FSynHttpServer.Active then
FSynHttpServer.InitHttps('server.crt', 'server.key', 'w1z2rd', '');
end;

procedure TForm2.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
if InitSSLInterface then
ShowMessage('SSL initialized')
else
begin
ShowMessage('SSL does not initialized');
CheckBox1.Checked := False;
end;
end;

procedure TForm2.SynHttpServer1HttpGet(Sender: TObject; Connection: TSynTcpSrvConnection;
Expand Down
25 changes: 13 additions & 12 deletions blcksock.pas
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ TBlockSocket = class(TObject)
FNonBlockMode: Boolean;
FMaxLineLength: Integer;
FMaxSendBandwidth: Integer;
FNextSend: FixedUInt;
FNextSend: UInt32;
FMaxRecvBandwidth: Integer;
FNextRecv: FixedUInt;
FNextRecv: UInt32;
FConvertLineEnd: Boolean;
FLastCR: Boolean;
FLastLF: Boolean;
Expand Down Expand Up @@ -377,7 +377,7 @@ TBlockSocket = class(TObject)
procedure DoMonitor(Writing: Boolean; const Buffer: TMemory; Len: Integer);
procedure DoCreateSocket;
procedure DoHeartbeat;
procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: UInt32);
procedure SetBandwidth(Value: Integer);
function TestStopFlag: Boolean;
procedure InternalSendStream(const Stream: TStream; WithSize, Indy: boolean); virtual;
Expand Down Expand Up @@ -1509,9 +1509,9 @@ TIPHeader = record
TTL: Byte;
Protocol: Byte;
CheckSum: Word;
SourceIp: FixedUInt;
DestIp: FixedUInt;
Options: FixedUInt;
SourceIp: UInt32;
DestIp: UInt32;
Options: UInt32;
end;

{:@abstract(Parent class of application protocol implementations.)
Expand Down Expand Up @@ -1858,7 +1858,8 @@ procedure TBlockSocket.DelayedOption(const Value: TSynaOption);
begin
if FSocket = INVALID_SOCKET then
begin
FDelayedOptions := FDelayedOptions + [Value];
SetLength(FDelayedOptions, Length(FDelayedOptions) + 1);
FDelayedOptions[High(FDelayedOptions)] := Value;
end
else
SetDelayedOption(Value);
Expand Down Expand Up @@ -2112,10 +2113,10 @@ procedure TBlockSocket.SetBandwidth(Value: Integer);
MaxRecvBandwidth := Value;
end;

procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: UInt32);
var
x: FixedUInt;
y: FixedUInt;
x: UInt32;
y: UInt32;
n: integer;
begin
if FStopFlag then
Expand Down Expand Up @@ -2355,7 +2356,7 @@ function TBlockSocket.RecvBufferEx(Buffer: TMemory; Len: Integer;
var
s: TSynaBytes;
rl, l: integer;
ti: FixedUInt;
ti: UInt32;
{$IFDEF CIL}
n: integer;
b: TMemory;
Expand Down Expand Up @@ -2528,7 +2529,7 @@ function TBlockSocket.RecvTerminated(Timeout: Integer; const Terminator: string)
CorCRLF: Boolean;
t: string;
tl: integer;
ti: FixedUInt;
ti: UInt32;
begin
ResetLastError;
Result := '';
Expand Down
Loading

0 comments on commit 992705f

Please sign in to comment.