使用 aardio 中的 simpleHttpServer 库实现 python 例程中的 HTTP 服务器功能
//简单服务器示例
import console;
import process;
import wsock.tcp.simpleHttpServer;
var srvHttp = wsock.tcp.simpleHttpServer()
srvHttp.documentRoot = "d:\"
console.log(srvHttp.getUrl());
process.execute(srvHttp.getUrl());
srvHttp.run(
function(response,request){
import fsys;
import inet.url;
if(!fsys.isDir(request.path) ) {
if( ..io.exist(request.path) )
response.loadcode(request.path)
else {
request.path = fsys.getParentDir(request.path)
}
}
response.write(" <title>Directory listing for /</title>
<body><h2>Directory listing for",request.path,"</h2><hr><ul>")
var file,dir = fsys.list(request.path,,"*.*");
for(i=1;#dir;1){
response.write('<li><a href="'
,inet.url.append(request.path,dir[ i ])
,'">'+tostring(i)+") ",dir[ i ],'</a><br>\r\n');
}
for(i=1;#file;1){
response.write('<li><a href="'
,inet.url.append(request.path,file[ i ])
,'">'+tostring(i)+") ",file[ i ],'</a><br>\r\n');
}
}
)
主题数 6 | 今日评论 0 | 今日主题 0 |