From 23cbfda066cdcdf4bb621e0d2cb663e917f887b8 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 18 Apr 2018 09:02:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ghttp.Cookie=E5=A2=9E=E5=8A=A0=E5=AF=B9http?= =?UTF-8?q?Only=E5=B1=9E=E6=80=A7=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/net/ghttp/http_server_cookie.go | 34 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/g/net/ghttp/http_server_cookie.go b/g/net/ghttp/http_server_cookie.go index f7b16afde..9d1d0db49 100644 --- a/g/net/ghttp/http_server_cookie.go +++ b/g/net/ghttp/http_server_cookie.go @@ -29,10 +29,11 @@ type Cookie struct { // cookie项 type CookieItem struct { - value string - domain string // 有效域名 - path string // 有效路径 - expire int // 过期时间 + value string + domain string // 有效域名 + path string // 有效路径 + expire int // 过期时间 + httpOnly bool } // 获取或者创建一个cookie对象,与传入的请求对应 @@ -57,7 +58,7 @@ func (c *Cookie) init() { c.mu.Lock() for _, v := range c.request.Cookies() { c.data[v.Name] = CookieItem { - v.Value, v.Domain, v.Path, v.Expires.Second(), + v.Value, v.Domain, v.Path, v.Expires.Second(), v.HttpOnly, } } c.mu.Unlock() @@ -84,12 +85,16 @@ func (c *Cookie) Set(key, value string) { } // 设置cookie,带详细cookie参数 -func (c *Cookie) SetCookie(key, value, domain, path string, maxage int) { +func (c *Cookie) SetCookie(key, value, domain, path string, maxAge int, httpOnly ... bool) { c.mu.Lock() - defer c.mu.Unlock() - c.data[key] = CookieItem { - value, domain, path, int(gtime.Second()) + maxage, + isHttpOnly := false + if len(httpOnly) > 0 { + isHttpOnly = httpOnly[0] } + c.data[key] = CookieItem { + value, domain, path, int(gtime.Second()) + maxAge, isHttpOnly, + } + c.mu.Unlock() } // 查询cookie @@ -127,11 +132,12 @@ func (c *Cookie) Output() { http.SetCookie( c.response.ResponseWriter, &http.Cookie { - Name : k, - Value : v.value, - Domain : v.domain, - Path : v.path, - Expires : time.Unix(int64(v.expire), 0), + Name : k, + Value : v.value, + Domain : v.domain, + Path : v.path, + Expires : time.Unix(int64(v.expire), 0), + HttpOnly : v.httpOnly, }, ) } From 91e999f7240b0de4ddb284d2af17af50769f8799 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 18 Apr 2018 09:03:49 +0800 Subject: [PATCH 2/2] README updates --- README.MD | 1 + TODO | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.MD b/README.MD index 294a68f47..a3fe9c4c2 100644 --- a/README.MD +++ b/README.MD @@ -40,6 +40,7 @@ gf是开源的,免费的,基于MIT协议进行分发,开源项目地址(gi * [执行对象注册](http://gf.johng.cn/590882) * [回调方法注册](http://gf.johng.cn/590883) * [事件回调注册](http://gf.johng.cn/590884) + * [服务性能分析](http://gf.johng.cn/592298) * [路由控制](http://gf.johng.cn/49437) * [Cookie](http://gf.johng.cn/494372) * [Session](http://gf.johng.cn/494373) diff --git a/TODO b/TODO index 0824aa2cb..dd0b1f3ef 100644 --- a/TODO +++ b/TODO @@ -1,12 +1,13 @@ +ON THE WAY: +1. gdb Where方法参数的改进,研究是否可以将string参数类型修改为interface{}; +2. 增加对于数据表Model的封装; +3. 增加fsnotify包支持; +4. 改进gcfg和gview的文件自动更新机制; +5. 将模板变量进行暴露,以便应用端可以进行灵活控制; + + DONE: 1. gconv完善针对不同类型的判断,例如:尽量减少sprintf("%v", xxx)来执行string类型的转换; 2. ghttp.Server请求执行中增加服务退出的方法,不再执行后续操作; 3. ghttp.Response对象完善并改进数据返回方法(Write/WriteString); - -ON THE WAY: -1. gdb Where方法参数的改进,研究是否可以将string参数类型修改为interface{}; -2. 增加对于数据表Model的封装; -3. ghttp.Server请求执行中增加服务退出的方法,不再执行后续操作; -4. 增加fsnotify包支持; -5. 改进gcfg和gview的文件自动更新机制; -6. 将模板变量进行暴露,以便应用端可以进行灵活控制; \ No newline at end of file +4. ghttp.Server请求执行中增加服务退出的方法,不再执行后续操作; \ No newline at end of file