mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb fixes
This commit is contained in:
parent
9e380e2886
commit
34a98e3df0
@ -106,6 +106,12 @@ pub fn (db DB) exec_param2(query string, param, param2 string) []pg.Row {
|
||||
param_vals[0] = param.str
|
||||
param_vals[1] = param2.str
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -74,11 +74,11 @@ fn (ctx mut Context) set_header(key, val string) {
|
||||
|
||||
pub fn (ctx Context) html(html string) {
|
||||
h := ctx.headers.join('\n')
|
||||
ctx.conn.write('HTTP/1.1 200 OK
|
||||
Content-Type: text/html
|
||||
$h
|
||||
ctx.conn.write('HTTP/1.1 200 OK
|
||||
Content-Type: text/html
|
||||
$h
|
||||
|
||||
$html
|
||||
$html
|
||||
')
|
||||
|
||||
}
|
||||
@ -86,8 +86,8 @@ $html
|
||||
pub fn run<T>(port int) {
|
||||
println('Running vweb app on http://localhost:$port ...')
|
||||
l := net.listen(port) or { panic('failed to listen') return }
|
||||
mut app_init := T{}
|
||||
app_init.init()
|
||||
mut app := T{}
|
||||
app.init()
|
||||
for {
|
||||
conn := l.accept() or {
|
||||
panic('accept() failed')
|
||||
@ -133,15 +133,15 @@ pub fn run<T>(port int) {
|
||||
url: vals[1]
|
||||
}
|
||||
println('vweb action = "$action"')
|
||||
mut app := T{
|
||||
vweb: Context{
|
||||
//mut app := T{
|
||||
app.vweb = Context{
|
||||
req: req
|
||||
conn: conn
|
||||
post_form: map[string]string{}
|
||||
static_files: map[string]string{}
|
||||
static_mime_types: map[string]string{}
|
||||
}
|
||||
}
|
||||
//}
|
||||
if req.method == 'POST' {
|
||||
app.vweb.parse_form(s)
|
||||
}
|
||||
@ -181,12 +181,12 @@ fn (ctx mut Context) parse_form(s string) {
|
||||
words := str_form.split('&')
|
||||
for word in words {
|
||||
println('parse form keyval="$word"')
|
||||
keyval := word.split('=')
|
||||
keyval := word.trim_space().split('=')
|
||||
if keyval.len != 2 { continue }
|
||||
key := keyval[0]
|
||||
val := keyval[1]
|
||||
//println('http form $key => $val')
|
||||
ctx.post_form[key] = http.unescape_url(val)
|
||||
val := http.unescape_url(keyval[1])
|
||||
println('http form "$key" => "$val"')
|
||||
ctx.post_form[key] = val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user