mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve parameters parsing for ghttp.Server
This commit is contained in:
@ -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 := ""
|
||||
|
||||
@ -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 {
|
||||
|
||||
52
net/ghttp/ghttp_server_config_mess.go
Normal file
52
net/ghttp/ghttp_server_config_mess.go
Normal file
@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user