Skip to content

Commit

Permalink
vweb: set_content_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Jun 27, 2020
1 parent c84bafb commit e666209
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions vlib/vweb/vweb.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 == '' {
Expand Down

0 comments on commit e666209

Please sign in to comment.