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 ...
随机推荐
- oracle行转列
wm_concat()函数 --创建表 create table test(id number,name varchar2(20)); --插入数据 insert into test values(1 ...
- LeetCode(10):正则表达式匹配
Hard! 题目描述: 给定一个字符串 (s) 和一个字符模式 (p).实现支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符. '*' 匹配零个或多个前面的元素. 匹配应该覆盖整 ...
- 【hadoop】har://
来源:http://hadoop.apache.org/docs/r1.0.4/cn/hadoop_archives.html 在hadoop代码中发现了一个很奇怪的路径,由har://开头.经查询, ...
- react 的JSX语法需要注意哪些点?
注释方式 ReactDOM.render( <div> {/*JSX 中的注释方式*/} </div>, document.getElementById('root') ) j ...
- BootStrap fileinput.js文件上传组件实例代码
1.首先我们下载好fileinput插件引入插件 ? 1 2 3 <span style="font-size:14px;"><link type="t ...
- Ubuntu 下 vi 输入方向键会变成 ABCD 的解决方法
Ubuntu 下 vi 输入方向键会变成 ABCD,这是 Ubuntu 预装的是 vim tiny 版本,安装 vim full 版本即可解决. 先卸载vim-tiny: $ sudo apt-get ...
- [转] 使用moment.js轻松管理日期和时间
当前时间:moment().format('YYYY-MM-DD HH:mm:ss'); 2017-03-01 16:30:12 今天是星期几:moment().format('d'); 3 Unix ...
- javascript研究小组知识库
http://hzjavaeyer.group.iteye.com/group/wiki?category_id=0
- @repository的含义,并且有时候却不用写,为什么?
//最后发现是这样的:@repository跟@Service,@Compent,@Controller这4种注解是没什么本质区别,都是声明作用,取不同的名字只是为了更好区分各自的功能.下图更多的作用 ...
- SOAP port
To determine the SOAP port on WebSphere Base: Server Types > WebSphere application servers > [ ...