httpserver/static.spl: add individual settings for bufsize and client-cache

This commit is contained in:
Daniella 2024-10-14 17:10:46 +02:00
parent 210eaade3a
commit e72baba154
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -8,6 +8,8 @@
1024 net:http:server:=bufsize
construct net:http:server:_static_ext_server {
bufsize
client-cache
cached-files
;
get-cached-files { cached-files | with this ;
@ -17,18 +19,24 @@ construct net:http:server:_static_ext_server {
construct net:http:server:_static_ext_Request {
;
get-bufsize { bufsize | with this ;
this:bufsize net:http:server:bufsize or
}
get-client-cache { client-cache | with this ;
this:client-cache net:http:server:client-cache or
}
serve-file { this | with filepath path type this ;
this:path path eq if {
filepath StreamTypes:file:create<0>:read-to-end<net:http:server:bufsize> this:write-ok:write-content-type<type>:write-body:finish;
filepath StreamTypes:file:create<0>:read-to-end<this:get-bufsize> this:write-ok:write-content-type<type>:write-body:finish;
}
this
}
serve-file-cached { this | with filepath path type this ;
this:path path eq if {
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>
pop filepath StreamTypes:file:create<0>:read-to-end<this:get-bufsize> dup this:server:cached-files:set;<filepath>
}
def cache net:http:server:client-cache =cache
def cache this:get-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