mirror of
https://gitee.com/johng/gf
synced 2026-07-06 13:42:46 +08:00
改进ghttp.Request.parsedPost为*gtype.Bool类型,以保证并发安全性
This commit is contained in:
@ -12,12 +12,13 @@ import (
|
||||
"net/url"
|
||||
"gitee.com/johng/gf/g/util/gconv"
|
||||
"gitee.com/johng/gf/g/encoding/gjson"
|
||||
"gitee.com/johng/gf/g/container/gtype"
|
||||
)
|
||||
|
||||
// 请求对象
|
||||
type Request struct {
|
||||
http.Request
|
||||
parsedPost bool // POST参数是否已经解析
|
||||
parsedPost *gtype.Bool // POST参数是否已经解析
|
||||
getvals *url.Values // GET参数
|
||||
Id int // 请求id(唯一)
|
||||
Server *Server // 请求关联的服务器对象
|
||||
@ -36,9 +37,9 @@ func (r *Request) initGet() {
|
||||
|
||||
// 初始化POST请求参数
|
||||
func (r *Request) initPost() {
|
||||
if !r.parsedPost {
|
||||
if !r.parsedPost.Val() {
|
||||
// 快速保存,尽量避免并发问题
|
||||
r.parsedPost = true
|
||||
r.parsedPost.Set(true)
|
||||
// MultiMedia表单请求解析允许最大使用内存:1GB
|
||||
r.ParseMultipartForm(1024*1024*1024)
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"path/filepath"
|
||||
"gitee.com/johng/gf/g/os/gfile"
|
||||
"gitee.com/johng/gf/g/encoding/ghtml"
|
||||
"gitee.com/johng/gf/g/container/gtype"
|
||||
)
|
||||
|
||||
// 默认HTTP Server处理入口,http包底层默认使用了gorutine异步处理请求,所以这里不再异步执行
|
||||
@ -38,10 +39,11 @@ func (s *Server)handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
// 构造请求参数对象
|
||||
request := &Request{
|
||||
Id : s.servedCount.Add(1),
|
||||
Server : s,
|
||||
Request : *r,
|
||||
Response : &Response {
|
||||
parsedPost : gtype.NewBool(),
|
||||
Id : s.servedCount.Add(1),
|
||||
Server : s,
|
||||
Request : *r,
|
||||
Response : &Response {
|
||||
ResponseWriter : w,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user