"base.spl" import "../stream.spl" import "_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 { bufsize client-cache cached-files ; get-cached-files { cached-files | with this ; this:cached-files dup not if { pop MicroMap:new dup this:=cached-files } } } 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 this:write-ok:write-content-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 dup this:server:cached-files:set; } 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:write-body:finish; } this } serve-string { this | with string path type this ; this:path path eq if { string this:write-ok:write-content-type:write-str-body:finish; } this } serve-html { this | with this ; "text/html" this:serve-file } serve-html-cached { this | with this ; "text/html" this:serve-file-cached } serve-html-string { this | with this ; "text/html" this:serve-string } } include net:http:server:_static_ext_server in net:http:Server include net:http:server:_static_ext_Request in net:http:server:Request