MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Prepare

Method Prepare

internal/nodes/http_writer.go:105–155  ·  view source on GitHub ↗

Prepare 准备输出

(resp *http.Response, size int64, status int, enableCache bool)

Source from the content-addressed store, hash-verified

103
104// Prepare 准备输出
105func (this *HTTPWriter) Prepare(resp *http.Response, size int64, status int, enableCache bool) (delayHeaders bool) {
106 // 清理以前数据,防止重试时发生异常错误
107 if this.compressionCacheWriter != nil {
108 _ = this.compressionCacheWriter.Discard()
109 this.compressionCacheWriter = nil
110 }
111
112 if this.cacheWriter != nil {
113 _ = this.cacheWriter.Discard()
114 this.cacheWriter = nil
115 }
116
117 // 新的请求相关数据
118 this.size = size
119 this.statusCode = status
120
121 // 是否为区间请求
122 this.isPartial = status == http.StatusPartialContent
123
124 // 不支持对GET以外的方法返回的Partial内容的缓存
125 if this.isPartial && this.req.Method() != http.MethodGet {
126 enableCache = false
127 }
128
129 if resp != nil && resp.Body != nil {
130 cacheReader, ok := resp.Body.(caches.Reader)
131 if ok {
132 this.cacheReader = cacheReader
133 }
134
135 this.rawReader = resp.Body
136
137 if enableCache {
138 this.PrepareCache(resp, size)
139 }
140 if !this.isPartial {
141 this.PrepareWebP(resp, size)
142 }
143 this.PrepareCompression(resp, size)
144 }
145
146 // 是否限速写入
147 if this.req.web != nil &&
148 this.req.web.RequestLimit != nil &&
149 this.req.web.RequestLimit.IsOn &&
150 this.req.web.RequestLimit.OutBandwidthPerConnBytes() > 0 {
151 this.writer = writers.NewRateLimitWriter(this.req.RawReq.Context(), this.writer, this.req.web.RequestLimit.OutBandwidthPerConnBytes())
152 }
153
154 return
155}
156
157// PrepareCache 准备缓存
158func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {

Callers 6

doRootMethod · 0.45
doPageLookupMethod · 0.45
doFastcgiMethod · 0.45
doCacheReadMethod · 0.45
doOriginRequestMethod · 0.45
doURLMethod · 0.45

Calls 7

PrepareCacheMethod · 0.95
PrepareWebPMethod · 0.95
PrepareCompressionMethod · 0.95
NewRateLimitWriterFunction · 0.92
MethodMethod · 0.80
ContextMethod · 0.80
DiscardMethod · 0.65

Tested by

no test coverage detected