1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

orm: bool support; vweb fixes

This commit is contained in:
Alexander Medvednikov
2019-12-09 17:10:44 +03:00
parent 32b0225079
commit 6f49d4c1d2
6 changed files with 36 additions and 15 deletions

View File

@ -41,26 +41,34 @@ pub:
// TODO Response
mut:
headers string // response headers
done bool
}
pub fn (ctx Context) html(html string) {
if ctx.done { return }
//println('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n$ctx.headers\r\n\r\n$html')
ctx.conn.write('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n$ctx.headers\r\n\r\n$html') or { panic(err) }
}
pub fn (ctx Context) text(s string) {
ctx.conn.write('HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n$ctx.headers\r\n\r\n $s') or { panic(err) }
pub fn (ctx mut Context) text(s string) {
if ctx.done { return }
ctx.conn.write('HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n' +
'$ctx.headers\r\n$s') or { panic(err) }
ctx.done = true
}
pub fn (ctx Context) json(s string) {
if ctx.done { return }
ctx.conn.write('HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n$ctx.headers\r\n\r\n$s') or { panic(err) }
}
pub fn (ctx Context) redirect(url string) {
if ctx.done { return }
ctx.conn.write('HTTP/1.1 302 Found\r\nLocation: $url\r\n$ctx.headers\r\n\r\n') or { panic(err) }
}
pub fn (ctx Context) not_found(s string) {
if ctx.done { return }
ctx.conn.write(HTTP_404) or { panic(err) }
}