mormot支持https
mormot支持https
将ssl证书导入电脑系统,以Windows 10为例:
运行 mmc









证书导入成功后,双击证书,查看证书指纹:

第二项工作:将证书与https绑定:
以管理员身份启动cmd,输入下列命令:
netsh http add sslcert ipport=0.0.0.0:443 certhash=3a0a8fa7cbcab141e102eaab457b1299af8f82cc appid={FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}
第三项工作:修改Delphi源程序:
program HttpApiServer;
{$APPTYPE CONSOLE}
{$I Synopse.inc}
//['{FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}']
//netsh http add sslcert ipport=0.0.0.0:443 certhash=3a0a8fa7cbcab141e102eaab457b1299af8f82cc appid={FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}
//netsh http delete sslcert ipport=0.0.0.0:443
uses
{$I SynDprUses.inc} // use FastMM4 on older Delphi, or set FPC threads
SysUtils,
SynCommons,
SynZip,
SynCrtSock;
type
TTestServer = class
protected
fPath: TFileName;
fPort, fRoot: string;
fServer: THttpApiServer;
fHttps: Boolean;
function Process(Ctxt: THttpServerRequest): cardinal;
function ShowDirectory(Ctxt: THttpServerRequest;
const FileName: TFileName; FN: RawUTF8): cardinal;
public
constructor Create(const Path: TFileName);
destructor Destroy; override;
end;
{ TTestServer }
constructor TTestServer.Create(const Path: TFileName);
begin
fPath := IncludeTrailingPathDelimiter(Path);
fPort := '443';
fRoot := '/test';
fHttps := True;
fServer := THttpApiServer.Create(false);
fServer.AddUrl(fRoot, fPort, fHttps, '+', true);
fServer.RegisterCompress(CompressDeflate); // our server will deflate html :)
fServer.OnRequest := Process;
fServer.Clone(31); // will use a thread pool of 32 threads in total
end;
destructor TTestServer.Destroy;
begin
fServer.RemoveUrl(fRoot, fPort, fHttps, '+');
fServer.Free;
inherited;
end;
{$WARN SYMBOL_PLATFORM OFF}
function TTestServer.Process(Ctxt: THttpServerRequest): cardinal;
var
FileName: TFileName;
FN: RawUTF8;
begin
write(Ctxt.Method, ' ', Ctxt.URL);
if not IdemPChar(pointer(Ctxt.URL), PAnsiChar(UpperCase(fRoot))) then begin
WriteLn(' End with 404');
result := 404;
exit;
end;
FN := StringReplaceChars(UrlDecode(copy(Ctxt.URL, Length(fRoot) + 1, maxInt)),
'/', '\');
if PosEx('..', FN) > 0 then begin
WriteLn(' .. End with 404');
result := 404; // circumvent obvious potential security leak
exit;
end;
while (FN <> '') and (FN[1] = '\') do
delete(FN, 1, 1);
while (FN <> '') and (FN[length(FN)] = '\') do
delete(FN, length(FN), 1);
FileName := fPath + UTF8ToString(FN);
writeLn(' => ' + FileName); //c5soft
if DirectoryExists(FileName) then begin
Result := ShowDirectory(ctxt, FileName, FN);
end else begin
// http.sys will send the specified file from kernel mode
Ctxt.OutContent := StringToUTF8(FileName);
Ctxt.OutContentType := HTTP_RESP_STATICFILE;
result := 200; // THttpApiServer.Execute will return 404 if not found
end;
end;
var
Msg: string;
function TTestServer.ShowDirectory(Ctxt: THttpServerRequest;
const FileName: TFileName; FN: RawUTF8): cardinal;
var
W: TTextWriter;
SRName, href: RawUTF8;
i: integer;
SR: TSearchRec;
cRoot: string;
procedure hrefCompute;
begin
SRName := StringToUTF8(SR.Name);
href := FN + StringReplaceChars(SRName, '\', '/');
end;
begin
if fRoot <> '/' then cRoot := fRoot + '/' else cRoot := fRoot;
// reply directory listing as html
W := TTextWriter.CreateOwnedStream;
try
W.Add('<html><body style="font-family: Arial">' +
'<h3>%</h3><p><table>', [FN]);
FN := StringReplaceChars(FN, '\', '/');
if FN <> '' then
FN := FN + '/';
if FindFirst(FileName + '\*.*', faDirectory, SR) = 0 then begin
repeat
if (SR.Attr and faDirectory <> 0) and (SR.Name <> '.') then begin
hrefCompute;
if SRName = '..' then begin
i := length(FN);
while (i > 0) and (FN[i] = '/') do dec(i);
while (i > 0) and (FN[i] <> '/') do dec(i);
href := copy(FN, 1, i);
end;
W.Add('<tr><td><b><a href="' + cRoot + '%">[%]</a></b></td></tr>', [href,
SRName]);
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
if FindFirst(FileName + '\*.*', faAnyFile - faDirectory - faHidden, SR) = 0 then begin
repeat
hrefCompute;
if SR.Attr and faDirectory = 0 then
W.Add('<tr><td><b><a href="' + cRoot +
'%">%</a></b></td><td>%</td><td>%</td></td></tr>',
[href, SRName, KB(SR.Size), DateTimeToStr(
{$IFDEF ISDELPHIXE2}SR.TimeStamp{$ELSE}FileDateToDateTime(SR.Time){$ENDIF})]);
until FindNext(SR) <> 0;
FindClose(SR);
end;
W.AddShort('</table></p><p><i>Powered by mORMot''s <strong>');
W.AddClassName(Ctxt.Server.ClassType);
W.AddShort('</strong></i> - ' +
'see <a href=https://synopse.info>https://synopse.info</a></p></body></html>');
Ctxt.OutContent := W.Text;
Ctxt.OutContentType := HTML_CONTENT_TYPE;
result := 200;
finally
W.Free;
end;
end;
begin
with TTestServer.Create('D:\Programs\Nginx\wwwroot\') do try
Msg := 'Server is now running on http';
if fHttps then Msg := Msg + 's';
msg := msg + '://localhost';
if fPort <> '80' then
Msg := Msg + ':' + fPort;
Msg := Msg + fRoot + #13#10#13#10'Press [Enter] to quit';
WriteLn(Msg);
readln;
finally
Free;
end;
end.
mormot支持https的更多相关文章
- node如何让一个端口同时支持https与http
众所周知node是一个高性能的web服务器,使用它可以很简单的创建一个http或https的服务器. 比如一个很简单的http服务器: var http = require('http'); var ...
- 如何让你的网站支持https
如何让你的网站支持https 当今世界的主流网站基本都是使用https对外界提供服务,甚至有某些公司建议完全使用https, 那么https是什么呢?请参考如下的图解,https是在我们通常说的tcp ...
- 让你的网站免费支持 HTTPS 及 Nginx 平滑升级
为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...
- 在iOS APP中使用H5显示百度地图时如何支持HTTPS?
现象: 公司正在开发一个iOSAPP,使用h5显示百度地图,但是发现同样的H5页面,在安卓可以显示出来,在iOS中就显示不出来. 原因分析: 但是现在iOS开发中,苹果已经要求在APP中的所有对外连接 ...
- iOS支持Https
http://oncenote.com/2014/10/21/Security-1-HTTPS/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_s ...
- 【转】如何在Windows+VS2005使用最新静态libcurl 7.35.0获取网页数据,支持HTTPS
地址: http://blog.csdn.net/hujkay作者:Jekkay Hu(34538980@qq.com)关键词:Windows,curl,ssl, visual c++ 2005, ...
- Web API应用支持HTTPS的经验总结
在我前面介绍的WebAPI文章里面,介绍了WebAPI的架构设计方面的内容,其中提出了现在流行的WebAPI优先的路线,这种也是我们开发多应用(APP.微信.微网站.商城.以及Winform等方面的整 ...
- loadrunner支持https协议的操作方法-经验总结
问题:用户portal支持https协议,用loadrunner录制登陆脚本时发现未录制到用户名和密码 录制到的脚本如下: login() { lr_think_time(10); web_url(& ...
- php中curl不支持https的解决办法
在php程序中使用curl去访问https站点时,报错:Protocol https not supported or disabled in libcurl 该错误信息表示php当时编译时使用的cu ...
随机推荐
- 【译】ASP.NET Identity Core 从零开始
原文出自Rui Figueiredo的博客,原文链接<ASP.NET Identity Core From Scratch> 译者注:这篇博文发布时正值Asp.Net Core 1.1 时 ...
- 常用Javascript集锦【不定期更新】
怎样用javascript删除某个HEML标签 document.getElementById(id).parentNode.removeChild(document.getElementById(i ...
- 再谈CentOS 7程序自启动
上次发现了/etc/init.d下已经没有启动脚本了,然后对于启动乱序自己在rc.local中重排. 其实想一想这些应用的自启动终归还是需要通过脚本来执行的. 一.脚本在哪里? /usr/lib/sy ...
- liunx 安装和解压命令
tar.gz格式 sudo tar -xvf file.tar.gz -C /目录/ //注意C为大写,-C /目录是可选的 zip sudo jar xvf file.zip //jar ...
- (五)消费Dubbo服务
前面我们搞了发布Dubbo服务,发布的服务就是用来消费的,所以我们这里来调用服务,消费下: 创建maven项目 dubbo-demo-consumer pom.xml配置下: <dependen ...
- Elasticsearch常用最全最常用工具清单
https://blog.csdn.net/ZYC88888/article/details/82872558
- 关于 contentWindow, contentDocument
没有永恒的技术只有变态的需求,没有好说的客户只有无奈的开发者, 如果iframe的出现是一个错误的话,iframe里边在来一个iframe那是错上加错,神话没有在远古的尘嚣中消失,却在怀具的今天不断上 ...
- CSS3 transition实现超酷图片墙动画效果
一.前面的感慨以前也陆陆续续试过CSS3的一些特性,文字投影,多边框等.但都是试试而已,知道有这么回事.今天,见到了一个新玩意,transition,认认真真的试了一下,经过,我懵了,我呆了,我傻了, ...
- 【Ubuntu】Ubuntu设置和查看环境变量
[Ubuntu]Ubuntu设置和查看环境变量 转载 https://blog.csdn.net/White_Idiot/article/details/78253004 1. 查看环境变量 查 ...
- sorted()排序详解
sorted()排序详解 http://wiki.python.org/moin/HowTo/Sorting?highlight=%28howto%29#The_Old_Way_Using_t ...