vweb: set_content_type()

pull/5542/head 0.1.28.1
Alexander Medvednikov 2020-06-27 23:22:37 +02:00
parent c84bafbdae
commit e666209fe2
1 changed files with 12 additions and 2 deletions

View File

@ -40,6 +40,7 @@ pub struct Context {
mut:
static_files map[string]string
static_mime_types map[string]string
content_type string = 'text/plain'
pub:
req http.Request
conn net.Socket
@ -74,12 +75,17 @@ pub fn (mut ctx Context) html(s string) {
pub fn (mut ctx Context) text(s string) Result {
ctx.send_response_to_client('text/plain', s)
return vweb.Result{}
return Result{}
}
pub fn (mut ctx Context) json(s string) Result {
ctx.send_response_to_client('application/json', s)
return vweb.Result{}
return Result{}
}
pub fn (mut ctx Context) ok(s string) Result {
ctx.send_response_to_client(ctx.content_type, s)
return Result{}
}
pub fn (mut ctx Context) redirect(url string) {
@ -101,6 +107,10 @@ pub fn (mut ctx Context) set_cookie(key, val string) {
ctx.add_header('Set-Cookie', '${key}=${val}; Secure; HttpOnly')
}
pub fn (mut ctx Context) set_content_type(typ string) {
ctx.content_type = typ
}
pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
mut cookie_header := ctx.get_header('cookie')
if cookie_header == '' {