mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: fix get_cookie() and redirect()
This commit is contained in:
parent
faf2f9920e
commit
b2874f1200
25
vlib/orm/orm_test.v
Normal file
25
vlib/orm/orm_test.v
Normal file
@ -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<Module>(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)
|
||||
*/
|
||||
}
|
@ -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,7 +54,7 @@ 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=', ';')
|
||||
}
|
||||
@ -88,8 +87,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 := T{}
|
||||
app.init()
|
||||
mut app_init := T{}
|
||||
app_init.init()
|
||||
for {
|
||||
conn := l.accept() or {
|
||||
panic('accept() failed')
|
||||
|
Loading…
Reference in New Issue
Block a user