mirror of
				https://github.com/TeaOSLab/EdgeCommon.git
				synced 2025-11-04 05:00:24 +08:00 
			
		
		
		
	集群服务设置--访问日志中可以设置是否只记录通用Header
This commit is contained in:
		@@ -18,9 +18,13 @@ type GlobalServerConfig struct {
 | 
			
		||||
		DomainMismatchAction *DomainMismatchAction `yaml:"domainMismatchAction" json:"domainMismatchAction"` // 不匹配时采取的动作
 | 
			
		||||
	} `yaml:"httpAll" json:"httpAll"`
 | 
			
		||||
 | 
			
		||||
	HTTPAccessLog struct {
 | 
			
		||||
		CommonRequestHeadersOnly bool `yaml:"commonRequestHeadersOnly" json:"commonRequestHeadersOnly"` // 只保留通用Header
 | 
			
		||||
	} `yaml:"httpAccessLog" json:"httpAccessLog"` // 访问日志配置
 | 
			
		||||
 | 
			
		||||
	Log struct {
 | 
			
		||||
		RecordServerError bool `yaml:"recordServerError" json:"recordServerError"` // 记录服务错误到运行日志
 | 
			
		||||
	} `yaml:"log" json:"log"`
 | 
			
		||||
	} `yaml:"log" json:"log"` // 运行日志配置
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *GlobalServerConfig) Init() error {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										203
									
								
								pkg/serverconfigs/http_common_headers.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								pkg/serverconfigs/http_common_headers.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,203 @@
 | 
			
		||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
 | 
			
		||||
 | 
			
		||||
package serverconfigs
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var HTTPCommonRequestHeaders = []string{
 | 
			
		||||
	"A-IM",
 | 
			
		||||
	"Accept",
 | 
			
		||||
	"Accept-Charset",
 | 
			
		||||
	"Accept-Datetime",
 | 
			
		||||
	"Accept-Encoding",
 | 
			
		||||
	"Accept-Language",
 | 
			
		||||
	"Access-Control-Request-Method",
 | 
			
		||||
	"Access-Control-Request-Headers",
 | 
			
		||||
	"Authorization",
 | 
			
		||||
	"Cache-Control",
 | 
			
		||||
	"Connection",
 | 
			
		||||
	"Content-Encoding",
 | 
			
		||||
	"Content-Length",
 | 
			
		||||
	"Content-MD5",
 | 
			
		||||
	"Content-Type",
 | 
			
		||||
	"Cookie",
 | 
			
		||||
	"Date",
 | 
			
		||||
	"Expect",
 | 
			
		||||
	"Forwarded",
 | 
			
		||||
	"From",
 | 
			
		||||
	"Host",
 | 
			
		||||
	"HTTP2-Settings",
 | 
			
		||||
	"If-Match",
 | 
			
		||||
	"If-Modified-Since",
 | 
			
		||||
	"If-None-Match",
 | 
			
		||||
	"If-Range",
 | 
			
		||||
	"If-Unmodified-Since",
 | 
			
		||||
	"Max-Forwards",
 | 
			
		||||
	"Origin",
 | 
			
		||||
	"Pragma",
 | 
			
		||||
	"Prefer",
 | 
			
		||||
	"Proxy-Authorization",
 | 
			
		||||
	"Range",
 | 
			
		||||
	"Referer",
 | 
			
		||||
	"TE",
 | 
			
		||||
	"Trailer",
 | 
			
		||||
	"Transfer-Encoding",
 | 
			
		||||
	"User-Agent",
 | 
			
		||||
	"Upgrade",
 | 
			
		||||
	"Via",
 | 
			
		||||
	"Warning",
 | 
			
		||||
	"Keep-Alive",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var HTTPCommonRequestHeaders2 = []string{
 | 
			
		||||
	"Upgrade-Insecure-Requests",
 | 
			
		||||
	"X-Requested-With",
 | 
			
		||||
	"DNT",
 | 
			
		||||
	"X-Forwarded-For",
 | 
			
		||||
	"X-Forwarded-Host",
 | 
			
		||||
	"X-Forwarded-Proto",
 | 
			
		||||
	"X-Forwarded-By",
 | 
			
		||||
	"X-Real-IP",
 | 
			
		||||
	"Front-End-Https",
 | 
			
		||||
	"X-Http-Method-Override",
 | 
			
		||||
	"X-ATT-DeviceId",
 | 
			
		||||
	"X-Wap-Profile",
 | 
			
		||||
	"Proxy-Connection",
 | 
			
		||||
	"X-UIDH",
 | 
			
		||||
	"X-Csrf-Token",
 | 
			
		||||
	"X-Request-ID",
 | 
			
		||||
	"X-Correlation-ID",
 | 
			
		||||
	"Correlation-ID",
 | 
			
		||||
	"Save-Data",
 | 
			
		||||
	"Device-Memory",
 | 
			
		||||
	"Downlink",
 | 
			
		||||
	"Early-Data",
 | 
			
		||||
	"ECT",
 | 
			
		||||
	"RTT",
 | 
			
		||||
	"Sec-CH-UA",
 | 
			
		||||
	"Sec-CH-UA-Arch",
 | 
			
		||||
	"Sec-CH-UA-Bitness",
 | 
			
		||||
	"Sec-CH-UA-Full-Version",
 | 
			
		||||
	"Sec-CH-UA-Full-Version-List",
 | 
			
		||||
	"Sec-CH-UA-Mobile",
 | 
			
		||||
	"Sec-CH-UA-Model",
 | 
			
		||||
	"Sec-CH-UA-Platform",
 | 
			
		||||
	"Sec-CH-UA-Platform-Version",
 | 
			
		||||
	"Sec-Fetch-Dest",
 | 
			
		||||
	"Sec-Fetch-Mode",
 | 
			
		||||
	"Sec-Fetch-Site",
 | 
			
		||||
	"Sec-Fetch-User",
 | 
			
		||||
	"Sec-GPC",
 | 
			
		||||
	"Service-Worker-Navigation-Preload",
 | 
			
		||||
	"Viewport-Width",
 | 
			
		||||
	"Want-Digest",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var HTTPCommonResponseHeaders = []string{
 | 
			
		||||
	"Accept-CH",
 | 
			
		||||
	"Access-Control-Allow-Origin",
 | 
			
		||||
	"Access-Control-Allow-Credentials",
 | 
			
		||||
	"Access-Control-Expose-Headers",
 | 
			
		||||
	"Access-Control-Max-Age",
 | 
			
		||||
	"Access-Control-Allow-Methods",
 | 
			
		||||
	"Access-Control-Allow-Headers",
 | 
			
		||||
	"Accept-Patch",
 | 
			
		||||
	"Accept-Post",
 | 
			
		||||
	"Accept-Ranges",
 | 
			
		||||
	"Age",
 | 
			
		||||
	"Allow",
 | 
			
		||||
	"Alt-Svc",
 | 
			
		||||
	"Cache-Control",
 | 
			
		||||
	"Clear-Site-Data",
 | 
			
		||||
	"Connection",
 | 
			
		||||
	"Content-Disposition",
 | 
			
		||||
	"Content-Encoding",
 | 
			
		||||
	"Content-Language",
 | 
			
		||||
	"Content-Length",
 | 
			
		||||
	"Content-Location",
 | 
			
		||||
	"Content-MD5",
 | 
			
		||||
	"Content-Range",
 | 
			
		||||
	"Content-Type",
 | 
			
		||||
	"Date",
 | 
			
		||||
	"Delta-Base",
 | 
			
		||||
	"ETag",
 | 
			
		||||
	"Expires",
 | 
			
		||||
	"IM",
 | 
			
		||||
	"Last-Modified",
 | 
			
		||||
	"Link",
 | 
			
		||||
	"Location",
 | 
			
		||||
	"P3P",
 | 
			
		||||
	"Pragma",
 | 
			
		||||
	"Preference-Applied",
 | 
			
		||||
	"Proxy-Authenticate",
 | 
			
		||||
	"Public-Key-Pins",
 | 
			
		||||
	"Retry-After",
 | 
			
		||||
	"Server",
 | 
			
		||||
	"Server-Timing",
 | 
			
		||||
	"Set-Cookie",
 | 
			
		||||
	"Strict-Transport-Security",
 | 
			
		||||
	"Trailer",
 | 
			
		||||
	"Transfer-Encoding",
 | 
			
		||||
	"Tk",
 | 
			
		||||
	"Upgrade",
 | 
			
		||||
	"Vary",
 | 
			
		||||
	"Via",
 | 
			
		||||
	"Warning",
 | 
			
		||||
	"WWW-Authenticate",
 | 
			
		||||
	"X-Frame-Options",
 | 
			
		||||
	"Keep-Alive",
 | 
			
		||||
	"Referrer-Policy",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var HTTPCommonResponseHeaders2 = []string{
 | 
			
		||||
	"Content-Security-Policy",
 | 
			
		||||
	"X-Content-Security-Policy",
 | 
			
		||||
	"Content-Security-Policy-Report-Only",
 | 
			
		||||
	"Cross-Origin-Embedder-Policy",
 | 
			
		||||
	"Cross-Origin-Opener-Policy",
 | 
			
		||||
	"Cross-Origin-Resource-Policy",
 | 
			
		||||
	"Digest",
 | 
			
		||||
	"X-WebKit-CSP",
 | 
			
		||||
	"Expect-CT",
 | 
			
		||||
	"NEL",
 | 
			
		||||
	"Permissions-Policy",
 | 
			
		||||
	"Refresh",
 | 
			
		||||
	"Report-To",
 | 
			
		||||
	"Status",
 | 
			
		||||
	"Timing-Allow-Origin",
 | 
			
		||||
	"X-Content-Duration",
 | 
			
		||||
	"X-Content-Type-Options",
 | 
			
		||||
	"X-Powered-By",
 | 
			
		||||
	"X-Redirect-By",
 | 
			
		||||
	"X-Request-ID",
 | 
			
		||||
	"X-Correlation-ID",
 | 
			
		||||
	"X-UA-Compatible",
 | 
			
		||||
	"X-XSS-Protection",
 | 
			
		||||
	"Sec-WebSocket-Accept",
 | 
			
		||||
	"SourceMap",
 | 
			
		||||
	"X-DNS-Prefetch-Control",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var allRequestHeaderMap = map[string]struct{}{}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	for _, headerName := range HTTPCommonRequestHeaders {
 | 
			
		||||
		allRequestHeaderMap[headerName] = struct{}{}
 | 
			
		||||
		allRequestHeaderMap[strings.ToLower(headerName)] = struct{}{}
 | 
			
		||||
		allRequestHeaderMap[http.CanonicalHeaderKey(headerName)] = struct{}{}
 | 
			
		||||
	}
 | 
			
		||||
	for _, headerName := range HTTPCommonRequestHeaders2 {
 | 
			
		||||
		allRequestHeaderMap[headerName] = struct{}{}
 | 
			
		||||
		allRequestHeaderMap[strings.ToLower(headerName)] = struct{}{}
 | 
			
		||||
		allRequestHeaderMap[http.CanonicalHeaderKey(headerName)] = struct{}{}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsCommonRequestHeader 判断某个HTTP请求Header名称是否为通用
 | 
			
		||||
func IsCommonRequestHeader(headerName string) bool {
 | 
			
		||||
	_, ok := allRequestHeaderMap[headerName]
 | 
			
		||||
	return ok
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user