From 252b8af422dfa4a8789ee775bf7540c17e9ea617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 8 Dec 2021 17:40:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=9C=A8=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E9=87=8C=E8=AE=BE=E7=BD=AEExpires=20Header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/http_cache_ref.go | 13 +++++++------ pkg/serverconfigs/http_expires_time_config.go | 16 ++++++++++++++++ pkg/serverconfigs/shared/time_duration.go | 5 ++++- 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 pkg/serverconfigs/http_expires_time_config.go diff --git a/pkg/serverconfigs/http_cache_ref.go b/pkg/serverconfigs/http_cache_ref.go index ba37940..e413b1f 100644 --- a/pkg/serverconfigs/http_cache_ref.go +++ b/pkg/serverconfigs/http_cache_ref.go @@ -13,12 +13,13 @@ type HTTPCacheRef struct { IsOn bool `yaml:"isOn" json:"isOn"` CachePolicyId int64 `yaml:"cachePolicyId" json:"cachePolicyId"` - Key string `yaml:"key" json:"key"` // 每个缓存的Key规则,里面可以有变量 - Life *shared.TimeDuration `yaml:"life" json:"life"` // 时间 - Status []int `yaml:"status" json:"status"` // 缓存的状态码列表 - MinSize *shared.SizeCapacity `yaml:"minSize" json:"minSize"` // 能够缓存的最小尺寸 - MaxSize *shared.SizeCapacity `yaml:"maxSize" json:"maxSize"` // 能够缓存的最大尺寸 - Methods []string `yaml:"methods" json:"methods"` // 支持的请求方法 + Key string `yaml:"key" json:"key"` // 每个缓存的Key规则,里面可以有变量 + Life *shared.TimeDuration `yaml:"life" json:"life"` // 时间 + ExpiresTime *HTTPExpiresTimeConfig `yaml:"expiresTime" json:"expiresTime"` // 客户端过期时间 + Status []int `yaml:"status" json:"status"` // 缓存的状态码列表 + MinSize *shared.SizeCapacity `yaml:"minSize" json:"minSize"` // 能够缓存的最小尺寸 + MaxSize *shared.SizeCapacity `yaml:"maxSize" json:"maxSize"` // 能够缓存的最大尺寸 + Methods []string `yaml:"methods" json:"methods"` // 支持的请求方法 SkipResponseCacheControlValues []string `yaml:"skipCacheControlValues" json:"skipCacheControlValues"` // 可以跳过的响应的Cache-Control值 SkipResponseSetCookie bool `yaml:"skipSetCookie" json:"skipSetCookie"` // 是否跳过响应的Set-Cookie Header diff --git a/pkg/serverconfigs/http_expires_time_config.go b/pkg/serverconfigs/http_expires_time_config.go new file mode 100644 index 0000000..c52bc31 --- /dev/null +++ b/pkg/serverconfigs/http_expires_time_config.go @@ -0,0 +1,16 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package serverconfigs + +import ( + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" +) + +// HTTPExpiresTimeConfig 发送到客户端的过期时间设置 +type HTTPExpiresTimeConfig struct { + IsPrior bool `yaml:"isPrior" json:"isPrior"` // 是否覆盖父级设置 + IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用 + Overwrite bool `yaml:"overwrite" json:"overwrite"` // 是否覆盖 + AutoCalculate bool `yaml:"autoCalculate" json:"autoCalculate"` // 是否自动计算 + Duration *shared.TimeDuration `yaml:"duration" json:"duration"` // 周期 +} diff --git a/pkg/serverconfigs/shared/time_duration.go b/pkg/serverconfigs/shared/time_duration.go index 594673c..1749ba4 100644 --- a/pkg/serverconfigs/shared/time_duration.go +++ b/pkg/serverconfigs/shared/time_duration.go @@ -13,9 +13,10 @@ const ( TimeDurationUnitMinute TimeDurationUnit = "minute" TimeDurationUnitHour TimeDurationUnit = "hour" TimeDurationUnitDay TimeDurationUnit = "day" + TimeDurationUnitWeek TimeDurationUnit = "week" ) -// 时间间隔 +// TimeDuration 时间间隔 type TimeDuration struct { Count int64 `yaml:"count" json:"count"` // 数量 Unit TimeDurationUnit `yaml:"unit" json:"unit"` // 单位 @@ -33,6 +34,8 @@ func (this *TimeDuration) Duration() time.Duration { return time.Duration(this.Count) * time.Hour case TimeDurationUnitDay: return time.Duration(this.Count) * 24 * time.Hour + case TimeDurationUnitWeek: + return time.Duration(this.Count) * 24 * 7 * time.Hour default: return time.Duration(this.Count) * time.Second }