httpserver/static.spl: write body as bytes when serving 'file'

This commit is contained in:
Daniella / Tove 2024-10-13 19:28:32 +02:00
parent c9463c6938
commit 4749c142fa
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -1,4 +1,5 @@
"base.spl" import
"../stream.spl" import
"_static_ext_server" net:http:server:register
"_static_ext_Request" net:http:server:register
@ -15,16 +16,16 @@ construct net:http:server:_static_ext_Request {
;
serve-file { this | with filepath path type this ;
this:path path eq if {
filepath read-file this:write-ok:write-content-type<type>:write-str-body:finish;
filepath StreamTypes:file:create<0>:read-to-end<1024> 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 read-file dup this:server:cached-files:set;<filepath>
pop filepath StreamTypes:file:create<0>:read-to-end<1024> dup this:server:cached-files:set;<filepath>
}
this:write-ok:write-content-type<type>:write-str-body:finish;
this:write-ok:write-content-type<type>:write-body:finish;
}
this
}