You are not logged in.
Pages: 1
The code is as follows:
fHttpServer := THttpApiServer.Create('');
fHttpServer.RegisterCompress(CompressGZip, 10);
fHttpServer.RegisterCompress(CompressDeflate, 10);
fHttpServer. AddUrl('', '8888', False, '127.0.0.1');
// fHttpServer. AddUrl('', '8888', False, '*');
//fHttpServer.AddUrl('', '8888', False, '+');
1. Whether I use * or+, the following three methods cannot be accessed:
http://127.0.0.1:8888
http://localhost:8888
http://192.168.1.9:8888 (Local intranet IP address)
2. After using Register Compress, use Ctxt.SetOutFile send a static file to the browser,but that has not been compressed.
Thank you.
Offline
How to register the URL as http.sys level? the code fHttpServer.add can't be registered?
Offline
The first problem has been solved. The second issue has not been resolved, as the output static HTML file is not compressed.
Offline
The static files is not compressed in the DoOnRequest:
function TGEApiServer.DoOnRequest(C: THttpServerRequestAbstract): cardinal;
var
sFile: string;
begin
var sUrl := UrlDecode(C.URL);
sFile := ExtractFilePath(ParamStr(0)) + 'dist\' + sUrl;
if FileExists(sFile) then
begin
Result := C.SetOutFile(sFile, False);
end
else if FileExists(sFile + '\index.html') then
begin
// eg: http://17.0.0.1 = http://127.0.0.1/index.html
sFile := sFile + '\index.html';
Result := C.SetOutFile(sFile, False);
end
else if sUrl = '/login' then
begin
Result := C.SetOutFile('.\dist\index.html', False);
end
else
begin
Result := 200;
end;
end;
Offline
Compression of files is not supported by the Windows API.
It can either return from memory or a file handle (see THttpChunkType).
So if you want compression, use SetOutContent(StringFromFile()).
Or even better, SetOutContent() with a cached value.
Offline
I am using SetOutContent(StringFromFile()),but it cannot output web pages properly.
Offline
What I mean is: I put some static files such as HTML, JS, CSS in the www directory and use THttpApiServer as a static web server. Currently, using SetOutContent (StringFromFile()) cannot achieve the goal.
Offline
Did you debug and see what is wrong?
How did you add the URI?
It sounds like if you don't understand what a http.sys domain is, and that you need to authorize the URI with admin rights at least once on the computer.
Offline
I just delphi the static files the DoOnRequest:
function TGEApiServer.DoOnRequest(C: THttpServerRequestAbstract): cardinal;
var
sFile: string;
begin
var sUrl := UrlDecode(C.URL);
sFile := ExtractFilePath(ParamStr(0)) + 'dist\' + sUrl;
if FileExists(sFile) then
begin
Result := C.SetOutFile(sFile, False);
end
else if FileExists(sFile + '\index.html') then
begin
// eg: http://17.0.0.1 = http://127.0.0.1/index.html
sFile := sFile + '\index.html';
Result := C.SetOutFile(sFile, False);
end
else if sUrl = '/login' then
begin
Result := C.SetOutFile('.\dist\index.html', False);
end
else
begin
Result := 200;
end;
end;
Offline
1) your code is unsafe because you can access any file on your system using ..\ patterns in the URI.
2) debug a little and see if it goes inside the method
3) http.sys needs to register the URI once with admin rights
Offline
Hi,
ab,What should safe code look like?and how to register the URI use code?
Oh, Mormot is so powerful, but its reference manual and demo are so few, making it difficult for beginners of Delphi to quickly get started.
Thanks for your help.
Offline
Pages: 1