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源程序:

  1. program HttpApiServer;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$I Synopse.inc}
  6.  
  7. //['{FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}']
  8. //netsh http add sslcert ipport=0.0.0.0:443 certhash=3a0a8fa7cbcab141e102eaab457b1299af8f82cc appid={FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}
  9. //netsh http delete sslcert ipport=0.0.0.0:443
  10.  
  11. uses
  12. {$I SynDprUses.inc} // use FastMM4 on older Delphi, or set FPC threads
  13. SysUtils,
  14. SynCommons,
  15. SynZip,
  16. SynCrtSock;
  17.  
  18. type
  19. TTestServer = class
  20. protected
  21. fPath: TFileName;
  22. fPort, fRoot: string;
  23. fServer: THttpApiServer;
  24. fHttps: Boolean;
  25. function Process(Ctxt: THttpServerRequest): cardinal;
  26. function ShowDirectory(Ctxt: THttpServerRequest;
  27. const FileName: TFileName; FN: RawUTF8): cardinal;
  28. public
  29. constructor Create(const Path: TFileName);
  30. destructor Destroy; override;
  31. end;
  32.  
  33. { TTestServer }
  34.  
  35. constructor TTestServer.Create(const Path: TFileName);
  36. begin
  37. fPath := IncludeTrailingPathDelimiter(Path);
  38. fPort := '443';
  39. fRoot := '/test';
  40. fHttps := True;
  41. fServer := THttpApiServer.Create(false);
  42. fServer.AddUrl(fRoot, fPort, fHttps, '+', true);
  43. fServer.RegisterCompress(CompressDeflate); // our server will deflate html :)
  44. fServer.OnRequest := Process;
  45. fServer.Clone(31); // will use a thread pool of 32 threads in total
  46. end;
  47.  
  48. destructor TTestServer.Destroy;
  49. begin
  50. fServer.RemoveUrl(fRoot, fPort, fHttps, '+');
  51. fServer.Free;
  52. inherited;
  53. end;
  54.  
  55. {$WARN SYMBOL_PLATFORM OFF}
  56.  
  57. function TTestServer.Process(Ctxt: THttpServerRequest): cardinal;
  58. var
  59. FileName: TFileName;
  60. FN: RawUTF8;
  61. begin
  62. write(Ctxt.Method, ' ', Ctxt.URL);
  63. if not IdemPChar(pointer(Ctxt.URL), PAnsiChar(UpperCase(fRoot))) then begin
  64. WriteLn(' End with 404');
  65. result := 404;
  66. exit;
  67. end;
  68. FN := StringReplaceChars(UrlDecode(copy(Ctxt.URL, Length(fRoot) + 1, maxInt)),
  69. '/', '\');
  70. if PosEx('..', FN) > 0 then begin
  71. WriteLn(' .. End with 404');
  72. result := 404; // circumvent obvious potential security leak
  73. exit;
  74. end;
  75. while (FN <> '') and (FN[1] = '\') do
  76. delete(FN, 1, 1);
  77. while (FN <> '') and (FN[length(FN)] = '\') do
  78. delete(FN, length(FN), 1);
  79. FileName := fPath + UTF8ToString(FN);
  80. writeLn(' => ' + FileName); //c5soft
  81. if DirectoryExists(FileName) then begin
  82. Result := ShowDirectory(ctxt, FileName, FN);
  83. end else begin
  84. // http.sys will send the specified file from kernel mode
  85. Ctxt.OutContent := StringToUTF8(FileName);
  86. Ctxt.OutContentType := HTTP_RESP_STATICFILE;
  87. result := 200; // THttpApiServer.Execute will return 404 if not found
  88. end;
  89. end;
  90.  
  91. var
  92. Msg: string;
  93.  
  94. function TTestServer.ShowDirectory(Ctxt: THttpServerRequest;
  95. const FileName: TFileName; FN: RawUTF8): cardinal;
  96. var
  97. W: TTextWriter;
  98. SRName, href: RawUTF8;
  99. i: integer;
  100. SR: TSearchRec;
  101. cRoot: string;
  102.  
  103. procedure hrefCompute;
  104. begin
  105. SRName := StringToUTF8(SR.Name);
  106. href := FN + StringReplaceChars(SRName, '\', '/');
  107. end;
  108. begin
  109. if fRoot <> '/' then cRoot := fRoot + '/' else cRoot := fRoot;
  110. // reply directory listing as html
  111. W := TTextWriter.CreateOwnedStream;
  112. try
  113. W.Add('<html><body style="font-family: Arial">' +
  114. '<h3>%</h3><p><table>', [FN]);
  115. FN := StringReplaceChars(FN, '\', '/');
  116. if FN <> '' then
  117. FN := FN + '/';
  118. if FindFirst(FileName + '\*.*', faDirectory, SR) = 0 then begin
  119. repeat
  120. if (SR.Attr and faDirectory <> 0) and (SR.Name <> '.') then begin
  121. hrefCompute;
  122. if SRName = '..' then begin
  123. i := length(FN);
  124. while (i > 0) and (FN[i] = '/') do dec(i);
  125. while (i > 0) and (FN[i] <> '/') do dec(i);
  126. href := copy(FN, 1, i);
  127. end;
  128. W.Add('<tr><td><b><a href="' + cRoot + '%">[%]</a></b></td></tr>', [href,
  129. SRName]);
  130. end;
  131. until FindNext(SR) <> 0;
  132. FindClose(SR);
  133. end;
  134. if FindFirst(FileName + '\*.*', faAnyFile - faDirectory - faHidden, SR) = 0 then begin
  135. repeat
  136. hrefCompute;
  137. if SR.Attr and faDirectory = 0 then
  138. W.Add('<tr><td><b><a href="' + cRoot +
  139. '%">%</a></b></td><td>%</td><td>%</td></td></tr>',
  140. [href, SRName, KB(SR.Size), DateTimeToStr(
  141. {$IFDEF ISDELPHIXE2}SR.TimeStamp{$ELSE}FileDateToDateTime(SR.Time){$ENDIF})]);
  142. until FindNext(SR) <> 0;
  143. FindClose(SR);
  144. end;
  145. W.AddShort('</table></p><p><i>Powered by mORMot''s <strong>');
  146.  
  147. W.AddClassName(Ctxt.Server.ClassType);
  148.  
  149. W.AddShort('</strong></i> - ' +
  150. 'see <a href=https://synopse.info>https://synopse.info</a></p></body></html>');
  151. Ctxt.OutContent := W.Text;
  152. Ctxt.OutContentType := HTML_CONTENT_TYPE;
  153. result := 200;
  154. finally
  155. W.Free;
  156. end;
  157.  
  158. end;
  159.  
  160. begin
  161. with TTestServer.Create('D:\Programs\Nginx\wwwroot\') do try
  162. Msg := 'Server is now running on http';
  163. if fHttps then Msg := Msg + 's';
  164. msg := msg + '://localhost';
  165. if fPort <> '80' then
  166. Msg := Msg + ':' + fPort;
  167. Msg := Msg + fRoot + #13#10#13#10'Press [Enter] to quit';
  168. WriteLn(Msg);
  169. readln;
  170. finally
  171. Free;
  172. end;
  173. end.

  

mormot支持https的更多相关文章

  1. node如何让一个端口同时支持https与http

    众所周知node是一个高性能的web服务器,使用它可以很简单的创建一个http或https的服务器. 比如一个很简单的http服务器: var http = require('http'); var ...

  2. 如何让你的网站支持https

    如何让你的网站支持https 当今世界的主流网站基本都是使用https对外界提供服务,甚至有某些公司建议完全使用https, 那么https是什么呢?请参考如下的图解,https是在我们通常说的tcp ...

  3. 让你的网站免费支持 HTTPS 及 Nginx 平滑升级

    为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...

  4. 在iOS APP中使用H5显示百度地图时如何支持HTTPS?

    现象: 公司正在开发一个iOSAPP,使用h5显示百度地图,但是发现同样的H5页面,在安卓可以显示出来,在iOS中就显示不出来. 原因分析: 但是现在iOS开发中,苹果已经要求在APP中的所有对外连接 ...

  5. iOS支持Https

    http://oncenote.com/2014/10/21/Security-1-HTTPS/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_s ...

  6. 【转】如何在Windows+VS2005使用最新静态libcurl 7.35.0获取网页数据,支持HTTPS

    地址: http://blog.csdn.net/hujkay作者:Jekkay Hu(34538980@qq.com)关键词:Windows,curl,ssl,  visual c++ 2005, ...

  7. Web API应用支持HTTPS的经验总结

    在我前面介绍的WebAPI文章里面,介绍了WebAPI的架构设计方面的内容,其中提出了现在流行的WebAPI优先的路线,这种也是我们开发多应用(APP.微信.微网站.商城.以及Winform等方面的整 ...

  8. loadrunner支持https协议的操作方法-经验总结

    问题:用户portal支持https协议,用loadrunner录制登陆脚本时发现未录制到用户名和密码 录制到的脚本如下: login() { lr_think_time(10); web_url(& ...

  9. php中curl不支持https的解决办法

    在php程序中使用curl去访问https站点时,报错:Protocol https not supported or disabled in libcurl 该错误信息表示php当时编译时使用的cu ...

随机推荐

  1. C# 将某个方法去异步执行

    C# 将某个方法去异步执行 Task.Run(() => { string msgerror = SendPhoneCode.NewSendByTemplate(apply.PhoneNum, ...

  2. ASP.NET MVC3 Model的常用验证示例

    1.金额(10位整数,2位小数) #region 余额 /// <summary> /// 余额 /// </summary> [DisplayName("余额&qu ...

  3. 2018-11-3& maven

    https://www.cnblogs.com/clsn/p/7944116.html#auto_id_10 http://www.runoob.com/maven/maven-creating-pr ...

  4. 解决方案:centos运行shell脚本时报“$'\r': 未找到命令”

    =============================================== 2018/9/12_第1次修改                       ccb_warlock == ...

  5. python3 pandas DataFrame常见用法

    df = pandas.read_clipboard() df 获取索引和值 df.index df.values DataFrame的values属性将数据以二维ndarray形式返回,dtype类 ...

  6. css1-puchong1

    HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. 一:HTML DOM 树 ...

  7. excel 2016 for mac破解

    1: 首先去官网下载一个正版的: 2:再下载一个破解工具: 链接: http://pan.baidu.com/s/1i4AFHFf 密码: 3yf8 3:最后按照破解教程破解: http://jing ...

  8. MySQL 中国省市区SQL表数据

    MySQL 中国省市区SQL表数据   1.查省SELECT * FROM china WHERE china.Pid=02.查市SELECT * FROM chinaWHERE china.Pid= ...

  9. UVa140 Bandwidth 小剪枝+双射小技巧+枚举全排列+字符串的小处理

    给出一个图,找出其中的最小带宽的排列.具体要求见传送门:UVa140 这题有些小技巧可以简化代码的编写. 本题的实现参考了刘汝佳老师的源码,的确给了我许多启发,感谢刘老师. 思路: 建立双射关系:从字 ...

  10. MyBatis 从浅入深 随笔整理

    MyBatis? archetypeCatalog = internal 本文档单独出现的_parameter都标识为变量名 一.三个基本要素: 核心接口和类 MyBatis 核心配置文件 SQL映射 ...