diff --git a/net/ghttp/ghttp_request_post.go b/net/ghttp/ghttp_request_post.go index 9d852c2fa..cfb0cfc92 100644 --- a/net/ghttp/ghttp_request_post.go +++ b/net/ghttp/ghttp_request_post.go @@ -23,8 +23,7 @@ func (r *Request) initPost() { r.parsedPost = true if v := r.Header.Get("Content-Type"); v != "" && gstr.Contains(v, "multipart/") { // multipart/form-data, multipart/mixed - // MultiMedia表单请求解析允许最大使用内存:1GB - r.ParseMultipartForm(1024 * 1024 * 1024) + r.ParseMultipartForm(r.Server.config.FormParsingMemory) if len(r.PostForm) > 0 { // 重新组织数据格式,使用统一的数据Parse方式 params := "" diff --git a/net/ghttp/ghttp_server_config.go b/net/ghttp/ghttp_server_config.go index 5d6fe7116..6331d59ac 100644 --- a/net/ghttp/ghttp_server_config.go +++ b/net/ghttp/ghttp_server_config.go @@ -73,6 +73,7 @@ type ServerConfig struct { ErrorStack bool // Logging: 当产生错误时打印调用链详细堆栈 ErrorLogEnabled bool // Logging: 是否开启error log(默认开启) AccessLogEnabled bool // Logging: 是否开启access log(默认关闭) + FormParsingMemory int64 // Mess: 表单解析内存限制(byte) NameToUriType int // Mess: 服务注册时对象和方法名称转换为URI时的规则 GzipContentTypes []string // Mess: 允许进行gzip压缩的文件类型 DumpRouteMap bool // Mess: 是否在程序启动时默认打印路由表信息 @@ -105,6 +106,7 @@ var defaultServerConfig = ServerConfig{ ErrorLogEnabled: true, AccessLogEnabled: false, DumpRouteMap: true, + FormParsingMemory: 1024 * 1024 * 1024, RouterCacheExpire: 60, Rewrites: make(map[string]string), } @@ -287,41 +289,6 @@ func (s *Server) SetServerAgent(agent string) { s.config.ServerAgent = agent } -func (s *Server) SetGzipContentTypes(types []string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } - s.config.GzipContentTypes = types -} - -// 服务注册时对象和方法名称转换为URI时的规则 -func (s *Server) SetNameToUriType(t int) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } - s.config.NameToUriType = t -} - -// 是否在程序启动时打印路由表信息 -func (s *Server) SetDumpRouteMap(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } - s.config.DumpRouteMap = enabled -} - -// 设置路由缓存过期时间(秒) -func (s *Server) SetRouterCacheExpire(expire int) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } - s.config.RouterCacheExpire = expire -} - // 设置KeepAlive func (s *Server) SetKeepAlive(enabled bool) { if s.Status() == SERVER_STATUS_RUNNING { diff --git a/net/ghttp/ghttp_server_config_mess.go b/net/ghttp/ghttp_server_config_mess.go new file mode 100644 index 000000000..659beed04 --- /dev/null +++ b/net/ghttp/ghttp_server_config_mess.go @@ -0,0 +1,52 @@ +// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghttp + +import "github.com/gogf/gf/os/glog" + +func (s *Server) SetGzipContentTypes(types []string) { + if s.Status() == SERVER_STATUS_RUNNING { + glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) + return + } + s.config.GzipContentTypes = types +} + +// 服务注册时对象和方法名称转换为URI时的规则 +func (s *Server) SetNameToUriType(t int) { + if s.Status() == SERVER_STATUS_RUNNING { + glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) + return + } + s.config.NameToUriType = t +} + +// 是否在程序启动时打印路由表信息 +func (s *Server) SetDumpRouteMap(enabled bool) { + if s.Status() == SERVER_STATUS_RUNNING { + glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) + return + } + s.config.DumpRouteMap = enabled +} + +// 设置路由缓存过期时间(秒) +func (s *Server) SetRouterCacheExpire(expire int) { + if s.Status() == SERVER_STATUS_RUNNING { + glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) + return + } + s.config.RouterCacheExpire = expire +} + +func (s *Server) SetFormParsingMemory(maxMemory int64) { + if s.Status() == SERVER_STATUS_RUNNING { + glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) + return + } + s.config.FormParsingMemory = maxMemory +}