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 ...
随机推荐
- Shiro:授权控制
对容易忽略的地方记录如下: 1.需要引入下面2个依赖,具体版本根据自身环境修改: <dependency> <groupId>org.apache.geronimo.bundl ...
- java.util.concurrent.RejectedExecutionException
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@59f1ca76 rejec ...
- DOM文档对象模型简介
DOM简介 DOM是W3C(万维网联盟)的标准 "W3C文档对象模型DOM是中立于平台和语言的接口,它允许程序和脚本动态地访问和更新文档的内容.结构.样式".W3C DOM ...
- 2018-2019-2 网络对抗技术 20165301 Exp5 MSF基础应用
2018-2019-2 网络对抗技术 20165301 Exp5 MSF基础应用 实践原理 1.MSF攻击方法 主动攻击:扫描主机漏洞,进行攻击 攻击浏览器 攻击其他客户端 2.MSF的六个模块 查看 ...
- Java编程的逻辑 (1) - 数据和变量
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...
- Java编程的逻辑 (25) - 异常 (下)
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...
- .NetCore下使用Prometheus实现系统监控和警报 (一)介绍【译】
[译]原文https://prometheus.io/docs/introduction/overview 什么是Prometheus? Prometheus是一个开源系统监控和警报工具包,最初起源于 ...
- Kubernetes Master节点灾备恢复操作指南---升级版
本文档简述了Kubernetes主节点灾备恢复的相关步骤,供在发生k8s master崩溃时操作. 就算是在k8s里部署了etcd群集, 主节点控制组件的高可用节点,灾备恢复也是必须要实现的操作,才能 ...
- 远程执行shell
目前我的需求是在我的hadoop集群搭建起来前,能定时做一下简易指标的监控,目前我的方案就是在我的server机上,定时执行远程脚本出指标数据,然后通过python脚本发送邮件. 远程执行脚本如下: ...
- oj提交时常见错误归纳
Presentation Error: 常见的PE错误应该有以下的几种情况: 每行输出之后有空行 每两行输出之间有空行 一行中,每个输出数字(或字符串,等)之间有空格 一行中,每个输出数字(或字符串, ...