Merge branch 'se77en-master' into develop

This commit is contained in:
Javier Provecho Fernandez
2015-10-02 12:38:32 +02:00
2 changed files with 52 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"math"
"net"
"net/http"
"net/url"
"strings"
"time"
@ -325,6 +326,42 @@ func (c *Context) Header(key, value string) {
}
}
func (c *Context) SetCookie(
name string,
value string,
maxAge int,
path string,
domain string,
secure bool,
httpOnly bool,
) {
cookie := http.Cookie{}
cookie.Name = name
cookie.Value = url.QueryEscape(value)
cookie.MaxAge = maxAge
cookie.Path = "/"
if path != "" {
cookie.Path = path
}
cookie.Domain = domain
cookie.Secure = secure
cookie.HttpOnly = httpOnly
c.Writer.Header().Add("Set-Cookie", cookie.String())
}
func (c *Context) GetCookie(name string) (string, error) {
cookie, err := c.Request.Cookie(name)
if err != nil {
return "", err
}
val, _ := url.QueryUnescape(cookie.Value)
return val, nil
}
func (c *Context) Render(code int, r render.Render) {
c.writermem.WriteHeader(code)
if err := r.Render(c.Writer); err != nil {