[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
head
body
method path version
method raw-path version
path query
headers
wrote-body
;
@ -57,8 +58,21 @@ construct net:http:server:Request {
this:head:split<"\r\n"> this:=head
def iter this:head:iter =iter
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
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
iter:foreach<{ | with header ;
header:readf<"{}: {}"> dup if {
@ -70,7 +84,7 @@ construct net:http:server:Request {
head-str { str | with this ;
this:method
" " concat
this:path concat
this:raw-path concat
" HTTP/" concat
this:version concat
"\r\n" concat

View file

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

View file

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

View file

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