默认不同步写入压缩缓存/增加是否同步写入压缩缓存设置/去除默认content-type类型设置

This commit is contained in:
刘祥超
2022-02-24 20:13:05 +08:00
parent 1050231086
commit 211750eb8e

View File

@@ -387,10 +387,6 @@ func (this *HTTPWriter) PrepareCompression(resp *http.Response, size int64) {
// 尺寸和类型
var contentType = this.Header().Get("Content-Type")
if len(contentType) == 0 {
// 如果没有显式设置Content-Type我们就认为是 text/html
contentType = "text/html"
}
if !this.compressionConfig.MatchResponse(contentType, size, filepath.Ext(this.req.Path()), this.req.Format) {
return
}
@@ -427,7 +423,11 @@ func (this *HTTPWriter) PrepareCompression(resp *http.Response, size int64) {
header.Del("Content-Length")
// compression cache writer
if !this.isPartial && this.cacheStorage != nil && (this.cacheReader != nil || this.cacheWriter != nil) && !this.webpIsEncoding {
// 只有在本身内容已经缓存的情况下才会写入缓存防止同时写入缓存导致IO负载升高
if !this.isPartial &&
this.cacheStorage != nil &&
(this.cacheReader != nil || (this.cacheStorage.Policy().SyncCompressionCache && this.cacheWriter != nil)) &&
!this.webpIsEncoding {
var cacheKey = ""
var expiredAt int64 = 0