Merge branch 'master' of https://github.com/se77en/gin into se77en-master

This commit is contained in:
Javier Provecho Fernandez
2015-10-02 11:25:25 +02:00
2 changed files with 54 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"io"
"math"
"net/http"
"net/url"
"strings"
"time"
@ -321,6 +322,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 {
cookie, err := c.Request.Cookie(name)
if err != nil {
return ""
}
val, _ := url.QueryUnescape(cookie.Value)
return val
}
func (c *Context) Render(code int, r render.Render) {
c.writermem.WriteHeader(code)
if err := r.Render(c.Writer); err != nil {