vweb: fix json() and text() results
parent
288ea182a8
commit
02b846aa72
|
@ -24,8 +24,8 @@ pub fn (mut app App) init_once() {
|
||||||
pub fn (mut app App) init() {
|
pub fn (mut app App) init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) json_endpoint() {
|
pub fn (mut app App) json_endpoint() vweb.Result {
|
||||||
app.vweb.json('{"a": 3}')
|
return app.vweb.json('{"a": 3}')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) index() vweb.Result {
|
pub fn (mut app App) index() vweb.Result {
|
||||||
|
@ -37,11 +37,11 @@ pub fn (mut app App) index() vweb.Result {
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) text() {
|
pub fn (mut app App) text() vweb.Result {
|
||||||
app.vweb.text('Hello world from vweb')
|
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.set_cookie('cookie', 'test')
|
||||||
app.vweb.text('Headers: $app.vweb.headers')
|
return app.vweb.text('Headers: $app.vweb.headers')
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,12 +72,14 @@ pub fn (mut ctx Context) html(s string) {
|
||||||
ctx.send_response_to_client('text/html', s)
|
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)
|
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)
|
ctx.send_response_to_client('application/json', s)
|
||||||
|
return vweb.Result{}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut ctx Context) redirect(url string) {
|
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 }
|
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) {
|
pub fn (mut ctx Context) not_found() Result {
|
||||||
if ctx.done { return }
|
if ctx.done { return vweb.Result{} }
|
||||||
ctx.done = true
|
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) {
|
pub fn (mut ctx Context) set_cookie(key, val string) {
|
||||||
|
|
Loading…
Reference in New Issue