add cache for static http server

This commit is contained in:
Daniella 2024-10-14 16:36:45 +02:00
parent 51212e139a
commit 210eaade3a
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -4,6 +4,7 @@
"_static_ext_server" net:http:server:register
"_static_ext_Request" net:http:server:register
"bufsize" net:http:server:register
"client-cache" net:http:server:register
1024 net:http:server:=bufsize
construct net:http:server:_static_ext_server {
@ -27,7 +28,8 @@ construct net:http:server:_static_ext_Request {
filepath this:server:get-cached-files:get dup not if {
pop filepath StreamTypes:file:create<0>:read-to-end<net:http:server:bufsize> dup this:server:cached-files:set;<filepath>
}
this:write-ok:write-content-type<type>:write-body:finish;
def cache net:http:server:client-cache =cache
this:write-ok cache if { :write-header<"Cache-Control" "public, max-age=" cache _str concat> } :write-content-type<type>:write-body:finish;
}
this
}