[http/server] add query handling, [std] make or operator smarter

This commit is contained in:
Daniella / Tove 2024-09-20 12:43:25 +02:00
parent 706c4f023b
commit 416a310072
4 changed files with 25 additions and 13 deletions

View file

@ -29,7 +29,8 @@ construct net:http:server:Request {
stream stream
head head
body body
method path version method raw-path version
path query
headers headers
wrote-body wrote-body
; ;
@ -57,8 +58,21 @@ construct net:http:server:Request {
this:head:split<"\r\n"> this:=head this:head:split<"\r\n"> this:=head
def iter this:head:iter =iter def iter this:head:iter =iter
iter:next:readf<"{} {} HTTP/{}"> dup if { iter:next:readf<"{} {} HTTP/{}"> dup if {
dup:to-stack this:=version this:=path this:=method dup:to-stack this:=version this:=raw-path this:=method
} pop } pop
MicroMap:new this:=query
def p "{}?{}" this:raw-path:readf =p
this:raw-path
p if {
{ | with attrib ;
"{}={}" attrib:readf dup if {
dup:to-stack this:query:set;
} not if {
attrib "" this:query:set;
}
} "&" p:1:split:foreach
pop p:0
} this:=path
MicroMap:new this:=headers MicroMap:new this:=headers
iter:foreach<{ | with header ; iter:foreach<{ | with header ;
header:readf<"{}: {}"> dup if { header:readf<"{}: {}"> dup if {
@ -70,7 +84,7 @@ construct net:http:server:Request {
head-str { str | with this ; head-str { str | with this ;
this:method this:method
" " concat " " concat
this:path concat this:raw-path concat
" HTTP/" concat " HTTP/" concat
this:version concat this:version concat
"\r\n" concat "\r\n" concat

View file

@ -19,11 +19,16 @@ func argv {
func eputs { func eputs {
print print
} }
def import-transformers List:new =import-transformers
func isbplmod'import-transform { with s ; func isbplmod'import-transform { with s ;
"spl: [compat] transforming import " s concat println "spl: [compat] transforming import " s concat println
s:_char "#" :_char eq if { s:_char "#" :_char eq if {
"#nop.spl" =s "#nop.spl" =s
} }
{ with tf ;
s tf:call =s
} import-transformers:foreach
"spl: [compat] transformed to " s concat println "spl: [compat] transformed to " s concat println
s s
} }

View file

@ -42,7 +42,7 @@ construct _Iter {
join { str | with separator this ; join { str | with separator this ;
{ str | with accum item ; { str | with accum item ;
accum _str separator item _str concat concat accum _str separator item _str concat concat
} this:reduce:calculate } this:reduce:calculate "" or
} }
filter { FilterIter | with filter this ; filter { FilterIter | with filter this ;
filter this FilterIter:new filter this FilterIter:new

View file

@ -198,16 +198,9 @@ pub fn and(stack: &mut Stack) -> OError {
} }
pub fn or(stack: &mut Stack) -> OError { pub fn or(stack: &mut Stack) -> OError {
let a = stack.pop();
let b = stack.pop(); let b = stack.pop();
stack.push( let a = stack.pop();
Value::Int(if a.lock_ro().is_truthy() || b.lock_ro().is_truthy() { stack.push(if a.lock_ro().is_truthy() { a } else { b });
1
} else {
0
})
.spl(),
);
Ok(()) Ok(())
} }