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

vweb: fix json() and text() results

This commit is contained in:
Alexander Medvednikov 2020-06-27 13:56:15 +02:00
parent 288ea182a8
commit 02b846aa72
2 changed files with 14 additions and 11 deletions

View File

@ -24,8 +24,8 @@ pub fn (mut app App) init_once() {
pub fn (mut app App) init() {
}
pub fn (mut app App) json_endpoint() {
app.vweb.json('{"a": 3}')
pub fn (mut app App) json_endpoint() vweb.Result {
return app.vweb.json('{"a": 3}')
}
pub fn (mut app App) index() vweb.Result {
@ -37,11 +37,11 @@ pub fn (mut app App) index() vweb.Result {
return $vweb.html()
}
pub fn (mut app App) text() {
app.vweb.text('Hello world from vweb')
pub fn (mut app App) text() vweb.Result {
return app.vweb.text('Hello world from vweb')
}
pub fn (mut app App) cookie() {
pub fn (mut app App) cookie() vweb.Result {
app.vweb.set_cookie('cookie', 'test')
app.vweb.text('Headers: $app.vweb.headers')
return app.vweb.text('Headers: $app.vweb.headers')
}

View File

@ -72,12 +72,14 @@ pub fn (mut ctx Context) html(s string) {
ctx.send_response_to_client('text/html', s)
}
pub fn (mut ctx Context) text(s string) {
pub fn (mut ctx Context) text(s string) Result {
ctx.send_response_to_client('text/plain', s)
return vweb.Result{}
}
pub fn (mut ctx Context) json(s string) {
pub fn (mut ctx Context) json(s string) Result {
ctx.send_response_to_client('application/json', s)
return vweb.Result{}
}
pub fn (mut ctx Context) redirect(url string) {
@ -86,10 +88,11 @@ pub fn (mut ctx Context) redirect(url string) {
ctx.conn.send_string('HTTP/1.1 302 Found\r\nLocation: ${url}${ctx.headers}\r\n${headers_close}') or { return }
}
pub fn (mut ctx Context) not_found(s string) {
if ctx.done { return }
pub fn (mut ctx Context) not_found() Result {
if ctx.done { return vweb.Result{} }
ctx.done = true
ctx.conn.send_string(http_404) or { return }
ctx.conn.send_string(http_404) or {}
return vweb.Result{}
}
pub fn (mut ctx Context) set_cookie(key, val string) {