vweb fixes

pull/1445/head
Alexander Medvednikov 2019-08-03 01:35:36 +02:00
parent 9e380e2886
commit 34a98e3df0
2 changed files with 19 additions and 13 deletions

View File

@ -106,6 +106,12 @@ pub fn (db DB) exec_param2(query string, param, param2 string) []pg.Row {
param_vals[0] = param.str param_vals[0] = param.str
param_vals[1] = param2.str param_vals[1] = param2.str
res := C.PQexecParams(db.conn, query.str, 2, 0, param_vals, 0, 0, 0) res := C.PQexecParams(db.conn, query.str, 2, 0, param_vals, 0, 0, 0)
e := string(C.PQerrorMessage(db.conn))
if e != '' {
println('pg exec2 error:')
println(e)
return res_to_rows(res)
}
return res_to_rows(res) return res_to_rows(res)
} }

View File

@ -86,8 +86,8 @@ $html
pub fn run<T>(port int) { pub fn run<T>(port int) {
println('Running vweb app on http://localhost:$port ...') println('Running vweb app on http://localhost:$port ...')
l := net.listen(port) or { panic('failed to listen') return } l := net.listen(port) or { panic('failed to listen') return }
mut app_init := T{} mut app := T{}
app_init.init() app.init()
for { for {
conn := l.accept() or { conn := l.accept() or {
panic('accept() failed') panic('accept() failed')
@ -133,15 +133,15 @@ pub fn run<T>(port int) {
url: vals[1] url: vals[1]
} }
println('vweb action = "$action"') println('vweb action = "$action"')
mut app := T{ //mut app := T{
vweb: Context{ app.vweb = Context{
req: req req: req
conn: conn conn: conn
post_form: map[string]string{} post_form: map[string]string{}
static_files: map[string]string{} static_files: map[string]string{}
static_mime_types: map[string]string{} static_mime_types: map[string]string{}
} }
} //}
if req.method == 'POST' { if req.method == 'POST' {
app.vweb.parse_form(s) app.vweb.parse_form(s)
} }
@ -181,12 +181,12 @@ fn (ctx mut Context) parse_form(s string) {
words := str_form.split('&') words := str_form.split('&')
for word in words { for word in words {
println('parse form keyval="$word"') println('parse form keyval="$word"')
keyval := word.split('=') keyval := word.trim_space().split('=')
if keyval.len != 2 { continue } if keyval.len != 2 { continue }
key := keyval[0] key := keyval[0]
val := keyval[1] val := http.unescape_url(keyval[1])
//println('http form $key => $val') println('http form "$key" => "$val"')
ctx.post_form[key] = http.unescape_url(val) ctx.post_form[key] = val
} }
} }
} }