(req *http.Request)
| 408 | } |
| 409 | |
| 410 | func 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 | |
| 437 | func cacheFile(key string) string { |
| 438 | return path.Join(os.TempDir(), "hub", "api", key) |
no test coverage detected
searching dependent graphs…