diff --git a/examples/vweb/vweb_example.v b/examples/vweb/vweb_example.v index 8b34242d05..33c0e76129 100644 --- a/examples/vweb/vweb_example.v +++ b/examples/vweb/vweb_example.v @@ -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') } diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 657a35e4bf..41efe74d19 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -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) {