📝 update test/httptest.nas
This commit is contained in:
parent
12d7dde42d
commit
04806fc2c5
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -4,13 +4,9 @@ var sd=socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_IP);
|
||||||
socket.bind(sd,"127.0.0.1",8080);
|
socket.bind(sd,"127.0.0.1",8080);
|
||||||
socket.listen(sd,1);
|
socket.listen(sd,1);
|
||||||
|
|
||||||
var client=socket.accept(sd);
|
var httpheader="Http/1.1 200 OK\n\n";
|
||||||
println("request ip: ",client.ip);
|
var httptail="\n";
|
||||||
var rv=socket.recv(client.sd,1024);
|
var index="<html>
|
||||||
println(rv.str);
|
|
||||||
socket.send(client.sd,"Http/1.1 200 OK
|
|
||||||
|
|
||||||
<html>
|
|
||||||
<head>
|
<head>
|
||||||
<title> nasal-http-test-web </title>
|
<title> nasal-http-test-web </title>
|
||||||
</head>
|
</head>
|
||||||
|
@ -27,8 +23,34 @@ socket.send(client.sd,"Http/1.1 200 OK
|
||||||
Now this project uses MIT license(2021/5/4). Edit it if you want, use this project to learn or create more interesting things(But don't forget me XD).
|
Now this project uses MIT license(2021/5/4). Edit it if you want, use this project to learn or create more interesting things(But don't forget me XD).
|
||||||
</text>
|
</text>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>";
|
||||||
|
var notfound="<html>
|
||||||
|
<head>
|
||||||
|
<title> nasal-http-test-web </title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<text>
|
||||||
|
404 NOT FOUND!
|
||||||
|
</text>
|
||||||
|
</body>
|
||||||
|
</html>";
|
||||||
|
|
||||||
");
|
while(1){
|
||||||
socket.closesocket(client.sd);
|
var client=socket.accept(sd);
|
||||||
|
var recieve_data=socket.recv(client.sd,1024);
|
||||||
|
if(!recieve_data.size){
|
||||||
|
println("[",client.ip,"] request connection closed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var first=split("\n",recieve_data.str)[0];
|
||||||
|
var (type,path)=split(" ",first)[0,1];
|
||||||
|
println("[",client.ip,"] request ",type," [",path,"]");
|
||||||
|
if(path=="/")
|
||||||
|
socket.send(client.sd,httpheader~index~httptail);
|
||||||
|
elsif(path=="/favicon.ico")
|
||||||
|
socket.send(client.sd,httpheader~io.fin("pic/favicon.ico")~httptail);
|
||||||
|
else
|
||||||
|
socket.send(client.sd,httpheader~notfound~httptail);
|
||||||
|
socket.closesocket(client.sd);
|
||||||
|
}
|
||||||
socket.closesocket(sd);
|
socket.closesocket(sd);
|
Loading…
Reference in New Issue