From b2874f12002468deb90b42cd45a450b4693f0f52 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 2 Aug 2019 06:57:35 +0200 Subject: [PATCH] vweb: fix get_cookie() and redirect() --- vlib/orm/orm_test.v | 25 +++++++++++++++++++++++++ vlib/vweb/vweb.v | 11 +++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 vlib/orm/orm_test.v diff --git a/vlib/orm/orm_test.v b/vlib/orm/orm_test.v new file mode 100644 index 0000000000..6837a12417 --- /dev/null +++ b/vlib/orm/orm_test.v @@ -0,0 +1,25 @@ +//import pg + +struct Mod { + id int + name string + url string + nr_downloads int +} + +fn test_orm() { +/* + db := pg.connect('vpm', 'alex') + nr_modules := select count from db.modules + mod := select from db.modules where id = 1 limit 1 + println(mod.name) + top_mods := select from db.modules where nr_downloads > 1000 order by nr_downloads desc limit 10 + top_mods := db.select from modules where nr_downloads > 1000 order by nr_downloads desc limit 10 + top_mods := db.select(m => m.nr_downloads > 1000).order_by(m => m.nr_downloads).desc().limit(10) + names := select name from db.modules // []string + + + n := db.q_int('select count(*) from modules') + println(n) +*/ +} diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index afdb53e218..3a43757d0c 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -38,8 +38,7 @@ $s pub fn (ctx Context) redirect(url string) { h := ctx.headers.join('\n') - ctx.conn.write(' -HTTP/1.1 302 Found + ctx.conn.write('HTTP/1.1 302 Found Location: $url $h ') @@ -55,9 +54,9 @@ pub fn (ctx mut Context) set_cookie(key, val string) { pub fn (ctx Context) get_cookie(key string) string { for h in ctx.req.headers2 { - if h.starts_with('Cookie:') { + if h.starts_with('Cookie:') || h.starts_with('cookie:') { cookie := h.right(7) - return cookie.find_between('$key=', ';') + return cookie.find_between(' $key=', ';') } } return '' @@ -88,8 +87,8 @@ $html pub fn run(port int) { println('Running vweb app on http://localhost:$port ...') l := net.listen(port) or { panic('failed to listen') return } - mut app := T{} - app.init() + mut app_init := T{} + app_init.init() for { conn := l.accept() or { panic('accept() failed')