forwardUncached forwards a request to the origin without caching. Used for HEAD and other non-GET methods that shouldn't consume cache space. Logs symmetrically with HandleProxy's GET path so a non-2xx PUT/POST (e.g. an S3 501 on a parquet write) is visible in Loki — without this, the non-cached pa
(w http.ResponseWriter, r *http.Request)
| 700 | case <-timer.C: |
| 701 | return true |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | func isRetriableOriginFetchError(err error) bool { |
| 706 | if err == nil { |
| 707 | return false |
| 708 | } |
| 709 | var oe *originStatusError |
| 710 | if errors.As(err, &oe) { |
| 711 | switch oe.status { |
| 712 | case http.StatusRequestTimeout, |
| 713 | http.StatusTooManyRequests, |
| 714 | http.StatusInternalServerError, |
| 715 | http.StatusBadGateway, |
| 716 | http.StatusServiceUnavailable, |
| 717 | http.StatusGatewayTimeout: |
| 718 | return true |
| 719 | default: |
| 720 | return false |
| 721 | } |
| 722 | } |
| 723 | if errors.Is(err, context.Canceled) { |
| 724 | return false |
| 725 | } |
| 726 | if errors.Is(err, context.DeadlineExceeded) { |
| 727 | return true |
| 728 | } |
| 729 | var netErr net.Error |
| 730 | if errors.As(err, &netErr) && netErr.Timeout() { |
| 731 | return true |
| 732 | } |
| 733 | msg := strings.ToLower(err.Error()) |
| 734 | return strings.Contains(msg, "connection reset by peer") || |
| 735 | strings.Contains(msg, "connection refused") || |
| 736 | strings.Contains(msg, "unexpected eof") || |
| 737 | strings.Contains(msg, "timeout") |
| 738 | } |
| 739 | |
| 740 | func originFetchOutcome(err error) string { |
| 741 | if err == nil { |
| 742 | return "success" |
| 743 | } |
| 744 | var oe *originStatusError |
| 745 | if errors.As(err, &oe) { |
| 746 | return "http_error" |
| 747 | } |
| 748 | if errors.Is(err, context.Canceled) { |
| 749 | return "canceled" |
| 750 | } |
| 751 | if errors.Is(err, context.DeadlineExceeded) { |
| 752 | return "timeout" |
| 753 | } |
| 754 | var netErr net.Error |
| 755 | if errors.As(err, &netErr) && netErr.Timeout() { |
| 756 | return "timeout" |
| 757 | } |
| 758 | return "error" |
| 759 | } |
no test coverage detected