ghttp updates

This commit is contained in:
John
2019-01-24 13:40:48 +08:00
parent ec130d0763
commit a488d1dbf7
3 changed files with 21 additions and 4 deletions

View File

@ -19,7 +19,7 @@ import (
// 请求对象
type Request struct {
http.Request
*http.Request
parsedGet bool // GET参数是否已经解析
parsedPost bool // POST参数是否已经解析
queryVars map[string][]string // GET参数
@ -46,7 +46,7 @@ func newRequest(s *Server, r *http.Request, w http.ResponseWriter) *Request {
routerVars : make(map[string][]string),
Id : s.servedCount.Add(1),
Server : s,
Request : *r,
Request : r,
Response : newResponse(s, w),
EnterTime : gtime.Microsecond(),
}
@ -59,7 +59,7 @@ func newRequest(s *Server, r *http.Request, w http.ResponseWriter) *Request {
// 获取Web Socket连接对象(如果是非WS请求会失败注意检查然会的error结果)
func (r *Request) WebSocket() (*WebSocket, error) {
if conn, err := wsUpgrader.Upgrade(r.Response.ResponseWriter.ResponseWriter, &r.Request, nil); err == nil {
if conn, err := wsUpgrader.Upgrade(r.Response.ResponseWriter.ResponseWriter, r.Request, nil); err == nil {
return &WebSocket {
conn,
}, nil

View File

@ -141,6 +141,9 @@ func (c *Cookie) Remove(key, domain, path string) {
// 输出到客户端
func (c *Cookie) Output() {
if len(c.data) == 0 {
return
}
for k, v := range c.data {
// 只有 expire != 0 的才是服务端在本次请求中设置的cookie
if v.expire == 0 {

View File

@ -9,6 +9,7 @@
package gstr_test
import (
"strings"
"testing"
)
@ -31,4 +32,17 @@ func Benchmark_BytesToString(b *testing.B) {
}
}
}
}
func Benchmark_Strings_ToUpper(b *testing.B) {
for i := 0; i < b.N; i++ {
strings.ToUpper(str)
}
}
func Benchmark_Strings_ToLower(b *testing.B) {
for i := 0; i < b.N; i++ {
strings.ToLower(str)
}
}