MCPcopy Create free account
hub / github.com/Azure/peerd / fstatRemote

Method fstatRemote

pkg/discovery/content/reader/reader.go:187–224  ·  view source on GitHub ↗

fstatRemote stats the file.

(log zerolog.Logger, req *http.Request, client *http.Client)

Source from the content-addressed store, hash-verified

185
186// fstatRemote stats the file.
187func (r *reader) fstatRemote(log zerolog.Logger, req *http.Request, client *http.Client) (int64, error) {
188 log.Debug().Str("url", req.URL.String()).Str("range", req.Header.Get("Range")).Msg("reader fstatRemote start")
189 defer log.Debug().Msg("reader fstatRemote stop")
190
191 resp, err := client.Do(req)
192 if err != nil {
193 log.Error().Err(err).Msg("reader fstatRemote error")
194 return 0, Error{resp, err}
195 }
196 defer func() {
197 if closeErr := resp.Body.Close(); closeErr != nil {
198 log.Error().Err(closeErr).Msg("reader fstatRemote body close error")
199 }
200 }()
201
202 if resp.StatusCode == 200 {
203 return resp.ContentLength, nil
204 }
205
206 if resp.StatusCode == 206 {
207 l := resp.ContentLength
208 rs := resp.Header.Get("Content-Range")
209 if rs == "" {
210 return l, nil
211 }
212
213 pos := strings.LastIndexByte(rs, '/')
214 if pos < 0 {
215 return l, nil
216 }
217
218 l, _ = strconv.ParseInt(rs[pos+1:], 10, 64)
219 return l, nil
220 }
221
222 log.Error().Err(err).Int("status", resp.StatusCode).Msg("reader fstatRemote error")
223 return 0, Error{resp, fmt.Errorf("unexpected response code: %d", resp.StatusCode)}
224}
225
226// preadRemote reads the file.
227func (r *reader) preadRemote(log zerolog.Logger, req *http.Request, client *http.Client, buf []byte) (int, error) {

Callers 2

FstatRemoteMethod · 0.95
doP2pMethod · 0.95

Calls 2

CloseMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected