MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / readPluginStoreResponse

Function readPluginStoreResponse

internal/pluginstore/github.go:243–265  ·  view source on GitHub ↗
(resp *http.Response, maxSize int64)

Source from the content-addressed store, hash-verified

241}
242
243func readPluginStoreResponse(resp *http.Response, maxSize int64) ([]byte, error) {
244 defer func() {
245 if errClose := resp.Body.Close(); errClose != nil {
246 log.WithError(errClose).Debug("failed to close plugin store response body")
247 }
248 }()
249 if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
250 body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
251 return nil, fmt.Errorf("unexpected status %d: %s", resp.StatusCode, strings.TrimSpace(string(body)))
252 }
253 reader := io.Reader(resp.Body)
254 if maxSize > 0 {
255 reader = io.LimitReader(resp.Body, maxSize+1)
256 }
257 data, errRead := io.ReadAll(reader)
258 if errRead != nil {
259 return nil, fmt.Errorf("read response: %w", errRead)
260 }
261 if maxSize > 0 && int64(len(data)) > maxSize {
262 return nil, fmt.Errorf("response exceeds maximum allowed size of %d bytes", maxSize)
263 }
264 return data, nil
265}
266
267func SelectReleaseAssets(release Release, id, version, goos, goarch string) (ReleaseAsset, ReleaseAsset, error) {
268 archiveName := ArchiveName(id, version, goos, goarch)

Callers 1

getMethod · 0.85

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected