结束WebP
()
| 1022 | |
| 1023 | // 结束WebP |
| 1024 | func (this *HTTPWriter) finishWebP() { |
| 1025 | // 处理WebP |
| 1026 | if this.webpIsEncoding { |
| 1027 | atomic.AddInt32(&webPThreads, 1) |
| 1028 | defer func() { |
| 1029 | atomic.AddInt32(&webPThreads, -1) |
| 1030 | }() |
| 1031 | |
| 1032 | var webpCacheWriter caches.Writer |
| 1033 | |
| 1034 | // 准备WebP Cache |
| 1035 | if this.cacheReader != nil || this.cacheWriter != nil { |
| 1036 | var cacheKey = "" |
| 1037 | var expiredAt int64 = 0 |
| 1038 | |
| 1039 | if this.cacheReader != nil { |
| 1040 | cacheKey = this.req.cacheKey + caches.SuffixWebP |
| 1041 | expiredAt = this.cacheReader.ExpiresAt() |
| 1042 | } else if this.cacheWriter != nil { |
| 1043 | cacheKey = this.cacheWriter.Key() + caches.SuffixWebP |
| 1044 | expiredAt = this.cacheWriter.ExpiredAt() |
| 1045 | } |
| 1046 | |
| 1047 | webpCacheWriter, _ = this.cacheStorage.OpenWriter(cacheKey, expiredAt, this.StatusCode(), -1, -1, -1, false) |
| 1048 | if webpCacheWriter != nil { |
| 1049 | // 写入Header |
| 1050 | for k, v := range this.Header() { |
| 1051 | if this.shouldIgnoreHeader(k) { |
| 1052 | continue |
| 1053 | } |
| 1054 | |
| 1055 | // 这里是原始的数据,不需要内容编码 |
| 1056 | if k == "Content-Encoding" || k == "Transfer-Encoding" { |
| 1057 | continue |
| 1058 | } |
| 1059 | for _, v1 := range v { |
| 1060 | _, err := webpCacheWriter.WriteHeader([]byte(k + ":" + v1 + "\n")) |
| 1061 | if err != nil { |
| 1062 | remotelogs.Error("HTTP_WRITER", "write webp cache failed: "+err.Error()) |
| 1063 | _ = webpCacheWriter.Discard() |
| 1064 | webpCacheWriter = nil |
| 1065 | break |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | if webpCacheWriter != nil { |
| 1071 | var teeWriter = writers.NewTeeWriterCloser(this.writer, webpCacheWriter) |
| 1072 | teeWriter.OnFail(func(err error) { |
| 1073 | if webpCacheWriter != nil { |
| 1074 | _ = webpCacheWriter.Discard() |
| 1075 | } |
| 1076 | webpCacheWriter = nil |
| 1077 | }) |
| 1078 | this.writer = teeWriter |
| 1079 | } |
| 1080 | } |
| 1081 | } |
no test coverage detected