MCPcopy
hub / github.com/mislav/hub / cacheKey

Function cacheKey

github/http.go:410–435  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

408}
409
410func cacheKey(req *http.Request) string {
411 path := strings.Replace(req.URL.EscapedPath(), "/", "-", -1)
412 if len(path) > 1 {
413 path = strings.TrimPrefix(path, "-")
414 }
415 host := req.Host
416 if host == "" {
417 host = req.URL.Host
418 }
419 hash := md5.New()
420 fmt.Fprintf(hash, "%d:", cacheVersion)
421 io.WriteString(hash, req.Header.Get("Accept"))
422 io.WriteString(hash, req.Header.Get("Authorization"))
423 queryParts := strings.Split(req.URL.RawQuery, "&")
424 sort.Strings(queryParts)
425 for _, q := range queryParts {
426 fmt.Fprintf(hash, "%s&", q)
427 }
428 if isGraphQL(req) && req.Body != nil {
429 if b, err := ioutil.ReadAll(req.Body); err == nil {
430 req.Body = ioutil.NopCloser(bytes.NewBuffer(b))
431 hash.Write(b)
432 }
433 }
434 return fmt.Sprintf("%s/%s_%x", host, path, hash.Sum(nil))
435}
436
437func cacheFile(key string) string {
438 return path.Join(os.TempDir(), "hub", "api", key)

Callers 1

performRequestUrlMethod · 0.85

Calls 3

isGraphQLFunction · 0.85
ReplaceMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…