Skip to content

Commit

Permalink
增加 mbedtls 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
winddriver committed Jan 15, 2019
1 parent c537d7b commit e8383ef
Show file tree
Hide file tree
Showing 180 changed files with 4,043 additions and 866 deletions.
76 changes: 62 additions & 14 deletions Net/Demos/CrossHttpConsole/uDM.pas
Expand Up @@ -5,12 +5,14 @@ interface
uses
{$IFDEF __CROSS_SSL__}
Net.CrossSslSocket,
{$IFDEF POSIX}
Net.CrossSslDemoCert,
{$ENDIF}
{$ENDIF}
System.SysUtils, System.Classes, System.Generics.Collections,
Net.CrossSocket.Base, Net.CrossSocket, Net.CrossHttpServer, Net.CrossHttpMiddleware;
Net.CrossSocket.Base,
Net.CrossSocket,
Net.CrossHttpServer,
Net.CrossHttpMiddleware,
Net.CrossHttpUtils;

type
IProgress = interface
Expand Down Expand Up @@ -200,17 +202,14 @@ procedure TDM.DataModuleCreate(Sender: TObject);
begin
FHttpServer := TCrossHttpServer.Create(0);
{$IFDEF __CROSS_SSL__}
{$IFDEF POSIX}
FHttpServer.SetCertificate(SSL_SERVER_CERT);
FHttpServer.SetPrivateKey(SSL_SERVER_PKEY);
{$ELSE}
FHttpServer.SetCertificateFile('server.crt');
FHttpServer.SetPrivateKeyFile('server.key');
{$ENDIF}
{$ENDIF}
FHttpServer.Addr := IPv4_ALL; // IPv4
// FHttpServer.Addr := IPv4_ALL; // IPv4
// FHttpServer.Addr := IPv6_ALL; // IPv6
FHttpServer.Addr := IPv4v6_ALL; // IPv4v6
FHttpServer.Port := AppCfg.ListenPort;
FHttpServer.Compressible := False;
FHttpServer.Compressible := True;

FHttpServer.OnConnected := _OnConnected;
FHttpServer.OnDisconnected := _OnDisconnected;
Expand Down Expand Up @@ -277,15 +276,15 @@ procedure TDM._CreateRouter;
;

FHttpServer
.Get('/null',
.Get('/hello',
procedure(ARequest: ICrossHttpRequest; AResponse: ICrossHttpResponse)
begin
AResponse.Send('');
AResponse.Send('Hello World');
end)
.Get('/hello',
.Get('/null',
procedure(ARequest: ICrossHttpRequest; AResponse: ICrossHttpResponse)
begin
AResponse.Send('Hello World');
AResponse.Send('');
end)
.Get('/yeah',
procedure(ARequest: ICrossHttpRequest; AResponse: ICrossHttpResponse)
Expand Down Expand Up @@ -348,6 +347,55 @@ procedure TDM._CreateRouter;
LWatch.Stop;
end);
end)
.Dir('/static', 'D:\')
.Dir('/g', 'G:\')
.Get('/file',
procedure(ARequest: ICrossHttpRequest; AResponse: ICrossHttpResponse)
var
LStream: TStream;
begin
LStream := TFile.OpenRead('d:\2.txt');
AResponse.ContentType := TMediaType.TEXT_HTML;
AResponse.SendNoCompress(LStream,
StrToInt64Def(ARequest.Query['pos'], 0),
StrToInt64Def(ARequest.Query['count'], 0),
procedure(AConnection: ICrossConnection; ASuccess: Boolean)
begin
FreeAndNil(LStream);
end);
end)
.Get('/stream',
procedure(ARequest: ICrossHttpRequest; AResponse: ICrossHttpResponse)
var
LStream: TMemoryStream;
begin
LStream := TMemoryStream.Create;
LStream.LoadFromFile('d:\2.txt');
AResponse.ContentType := TMediaType.TEXT_HTML;
AResponse.SendZCompress(LStream,
StrToInt64Def(ARequest.Query['pos'], 0),
StrToInt64Def(ARequest.Query['count'], 0),
TCompressType.ctGZip,
procedure(AConnection: ICrossConnection; ASuccess: Boolean)
begin
FreeAndNil(LStream);
end);
end)
.Get('/bytes',
procedure(ARequest: ICrossHttpRequest; AResponse: ICrossHttpResponse)
var
LBytes: TBytes;
begin
LBytes := TFile.ReadAllBytes('d:\2.txt');
AResponse.ContentType := TMediaType.TEXT_HTML;
AResponse.SendNoCompress(LBytes,
StrToInt64Def(ARequest.Query['pos'], 0),
StrToInt64Def(ARequest.Query['count'], 0),
procedure(AConnection: ICrossConnection; ASuccess: Boolean)
begin
LBytes := nil;
end);
end)
;

for I := 0 to AppCfg.DirMaps.Count - 1 do
Expand Down
301 changes: 230 additions & 71 deletions Net/Demos/TestCrossSocket/TestCrossSocket.dproj

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions Net/Demos/TestCrossSocket/uMain.pas
Expand Up @@ -11,11 +11,10 @@ interface
FMX.Controls.Presentation, FMX.Edit, FMX.EditBox, FMX.SpinBox,
System.Diagnostics, FMX.Objects,
{$IFDEF __SSL__}
Net.CrossSslSocket.Base,
Net.CrossSslSocket,
{$IFDEF POSIX}
Net.CrossSslDemoCert,
{$ENDIF}
{$ENDIF}
Net.SocketAPI, Net.CrossSocket.Base, Net.CrossSocket;

type
Expand Down Expand Up @@ -309,14 +308,8 @@ procedure TfmMain.FormCreate(Sender: TObject);
FRunWatch := TStopwatch.StartNew;

{$IFDEF __SSL__}
FSocket.InitSslCtx(SSLv23);
{$IFDEF POSIX}
FSocket.SetCertificate(SSL_SERVER_CERT);
FSocket.SetPrivateKey(SSL_SERVER_PKEY);
{$ELSE}
FSocket.SetCertificateFile('server.crt');
FSocket.SetPrivateKeyFile('server.key');
{$ENDIF}
{$ENDIF}

FTestProc :=
Expand Down
Binary file added Net/MbedObj/Android/libmbedtls.a
Binary file not shown.
Binary file added Net/MbedObj/Linux64/libmbedcrypto.so
Binary file not shown.
Binary file added Net/MbedObj/Linux64/libmbedtls.so
Binary file not shown.
Binary file added Net/MbedObj/Linux64/libmbedx509.so
Binary file not shown.
Binary file added Net/MbedObj/MbedTls.zip
Binary file not shown.
Binary file added Net/MbedObj/Win32/aes.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/aesni.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/arc4.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/aria.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/asn1parse.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/asn1write.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/base64.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/bignum.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/blowfish.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/camellia.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ccm.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/chacha20.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/chachapoly.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/cipher.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/cipher_wrap.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/cmac.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ctr_drbg.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/debug.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/des.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/dhm.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ecdh.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ecdsa.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ecjpake.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ecp.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ecp_curves.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/entropy.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/entropy_poll.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/error.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/gcm.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/havege.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/hkdf.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/hmac_drbg.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/md.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/md2.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/md4.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/md5.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/md_wrap.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/memory_buffer_alloc.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/nist_kw.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/oid.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/padlock.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pem.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pk.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pk_wrap.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pkcs11.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pkcs12.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pkcs5.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pkparse.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/pkwrite.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/platform.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/platform_util.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/poly1305.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ripemd160.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/rsa.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/rsa_internal.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/sha1.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/sha256.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/sha512.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ssl_cache.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ssl_ciphersuites.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ssl_cli.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ssl_cookie.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ssl_srv.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ssl_ticket.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/ssl_tls.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/threading.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/timing.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/version.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/version_features.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/x509.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/x509_create.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/x509_crl.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/x509_crt.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/x509_csr.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/x509write_crt.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/x509write_csr.obj
Binary file not shown.
Binary file added Net/MbedObj/Win32/xtea.obj
Binary file not shown.
Binary file added Net/MbedObj/Win64/aes.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/aesni.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/arc4.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/aria.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/asn1parse.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/asn1write.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/base64.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/bignum.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/blowfish.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/camellia.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ccm.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/chacha20.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/chachapoly.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/cipher.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/cipher_wrap.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/cmac.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ctr_drbg.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/debug.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/des.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/dhm.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ecdh.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ecdsa.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ecjpake.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ecp.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ecp_curves.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/entropy.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/entropy_poll.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/error.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/gcm.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/havege.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/hkdf.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/hmac_drbg.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/md.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/md2.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/md4.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/md5.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/md_wrap.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/memory_buffer_alloc.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/nist_kw.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/oid.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/padlock.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pem.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pk.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pk_wrap.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pkcs11.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pkcs12.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pkcs5.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pkparse.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/pkwrite.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/platform.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/platform_util.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/poly1305.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ripemd160.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/rsa.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/rsa_internal.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/sha1.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/sha256.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/sha512.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ssl_cache.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ssl_ciphersuites.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ssl_cli.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ssl_cookie.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ssl_srv.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ssl_ticket.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/ssl_tls.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/threading.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/timing.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/version.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/version_features.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/x509.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/x509_create.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/x509_crl.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/x509_crt.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/x509_csr.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/x509write_crt.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/x509write_csr.o
Binary file not shown.
Binary file added Net/MbedObj/Win64/xtea.o
Binary file not shown.
Binary file added Net/MbedObj/iOSDevice64/libmbedtls.a
Binary file not shown.
50 changes: 35 additions & 15 deletions Net/Net.CrossHttpParams.pas
Expand Up @@ -12,10 +12,17 @@
interface

uses
System.SysUtils, System.Classes, System.Generics.Collections,
System.Generics.Defaults, System.NetEncoding, System.IOUtils,
System.RegularExpressions, System.SyncObjs, System.Diagnostics,
System.DateUtils, Net.CrossHttpUtils;
System.SysUtils,
System.Classes,
System.Generics.Collections,
System.Generics.Defaults,
System.NetEncoding,
System.IOUtils,
System.RegularExpressions,
System.SyncObjs,
System.Diagnostics,
System.DateUtils,
Net.CrossHttpUtils;

type
TNameValue = record
Expand Down Expand Up @@ -331,7 +338,6 @@ TFormField = class
FFilePath: string;
FContentType: string;
FContentTransferEncoding: string;
FAutoDeleteFile: Boolean;
public
constructor Create;
destructor Destroy; override;
Expand Down Expand Up @@ -374,11 +380,6 @@ TFormField = class
/// </summary>
property FilePath: string read FFilePath;

/// <summary>
/// 对象释放时自动删除上传的文件
/// </summary>
property AutoDeleteFile: Boolean read FAutoDeleteFile write FAutoDeleteFile;

/// <summary>
/// 内容类型(只有文件才有该属性)
/// </summary>
Expand Down Expand Up @@ -503,6 +504,11 @@ TEnumerator = class(TEnumerator<TFormField>)
procedure SetExpiryTime(const Value: Integer);
procedure SetValue(const AName, AValue: string);

/// <summary>
/// 更新最后访问时间
/// </summary>
procedure Touch;

/// <summary>
/// 是否已过期
/// </summary>
Expand Down Expand Up @@ -559,6 +565,7 @@ TSessionBase = class abstract(TInterfacedObject, ISession)
public
constructor Create(const ASessionID: string); virtual; abstract;

procedure Touch; virtual;
function Expired: Boolean; virtual;

property SessionID: string read GetSessionID write SetSessionID;
Expand Down Expand Up @@ -809,7 +816,8 @@ TSessions = class(TSessionsBase)
implementation

uses
Utils.Utils, Utils.DateTime;
Utils.Utils,
Utils.DateTime;

{ TNameValue }

Expand Down Expand Up @@ -1268,9 +1276,6 @@ destructor TFormField.Destroy;
begin
FreeValue;

if FAutoDeleteFile and (FFilePath <> '') and TFile.Exists(FFilePath) then
TFile.Delete(FFilePath);

inherited;
end;

Expand Down Expand Up @@ -1352,7 +1357,18 @@ destructor THttpMultiPartFormData.Destroy;
end;

procedure THttpMultiPartFormData.Clear;
var
LField: TFormField;
begin
for LField in FPartFields do
begin
if FAutoDeleteFiles and TFile.Exists(LField.FilePath) then
begin
LField.FreeValue;
TFile.Delete(LField.FilePath);
end;
end;

FPartFields.Clear;
end;

Expand Down Expand Up @@ -1550,7 +1566,6 @@ function THttpMultiPartFormData.Decode(const ABuf: Pointer; ALen: Integer): Inte
LPartHeader := TEncoding.UTF8.GetString(FCurrentPartHeader.Bytes, 0, FCurrentPartHeader.Size - 4{#13#10#13#10});
FCurrentPartHeader.Clear;
FCurrentPartField := TFormField.Create;
FCurrentPartField.AutoDeleteFile := FAutoDeleteFiles;
__InitFormFieldByHeader(FCurrentPartField, LPartHeader);
FPartFields.Add(FCurrentPartField);

Expand Down Expand Up @@ -1694,6 +1709,11 @@ function TSessionBase.Expired: Boolean;
Result := (Now.SecondsDiffer(LastAccessTime) >= ExpiryTime);
end;

procedure TSessionBase.Touch;
begin
LastAccessTime := Now;
end;

{ TSession }

constructor TSession.Create(const ASessionID: string);
Expand Down
67 changes: 65 additions & 2 deletions Net/Net.CrossHttpRouter.pas
Expand Up @@ -41,6 +41,17 @@ TNetCrossRouter = class
/// 本地目录
/// </param>
class function Dir(const APath, ALocalDir, ADirParamName: string): TCrossHttpRouterProc2; static;

/// <summary>
/// 含有默认首页文件的静态文件路由
/// </summary>
/// <param name="ALocalDir">
/// 含有默认首页文件的本地目录
/// </param>
/// <param name="ADefIndexFiles">
/// 默认的首页文件,按顺序选择,先找到哪个就使用哪个
/// </param>
class function Index(const ALocalDir, AFileParamName: string; const ADefIndexFiles: TArray<string>): TCrossHttpRouterProc2; static;
end;

implementation
Expand All @@ -50,6 +61,58 @@ implementation

{ TNetCrossRouter }

class function TNetCrossRouter.Index(const ALocalDir, AFileParamName: string;
const ADefIndexFiles: TArray<string>): TCrossHttpRouterProc2;
var
LDefIndexFiles: TArray<string>;
begin
if (ADefIndexFiles <> nil) then
LDefIndexFiles := ADefIndexFiles
else
LDefIndexFiles := [
'index.html',
'main.html',
'index.js',
'main.js',
'index.htm',
'main.htm'
];

Result :=
procedure(ARequest: ICrossHttpRequest; AResponse: ICrossHttpResponse; var AHandled: Boolean)
var
LPath, LFile, LDefMainFile: string;
begin
LPath := ALocalDir;
LFile := ARequest.Params[AFileParamName];

if (LFile = '') then
begin
for LDefMainFile in LDefIndexFiles do
begin
LFile := TPath.Combine(LPath, LDefMainFile);
if TFile.Exists(LFile) then
begin
AResponse.SendFile(LFile);
AHandled := True;
Exit;
end;
end;
end else
begin
LFile := TPath.Combine(LPath, LFile);
if TFile.Exists(LFile) then
begin
AResponse.SendFile(LFile);
AHandled := True;
Exit;
end;
end;

AHandled := False;
end;
end;

class function TNetCrossRouter.Static(
const ALocalDir, AFileParamName: string): TCrossHttpRouterProc2;
begin
Expand Down Expand Up @@ -173,8 +236,8 @@ function BuildDirList(const ARealPath, ARequestPath, AHome: string): string;
LPath := _NormalizePath(APath);
LHome := _NormalizePath(AHome);

LPathArr := LPath.Split(['/', '\'], ExcludeEmpty);
LHomeArr := LHome.Split(['/', '\'], ExcludeEmpty);
LPathArr := LPath.Split(['/', '\'], TStringSplitOptions.ExcludeEmpty);
LHomeArr := LHome.Split(['/', '\'], TStringSplitOptions.ExcludeEmpty);
if Length(LHomeArr) > Length(LPathArr) then Exit('');

I := 0;
Expand Down

0 comments on commit e8383ef

Please sign in to comment.