| 813 | // TestHandleProxyNetworkErrorStill502: when the origin is fully |
| 814 | // unreachable (no HTTP response at all), 502 is still the right answer — |
| 815 | // there was no upstream status to forward, and httpfs's "retry on 5xx" |
| 816 | // behaviour is appropriate here. |
| 817 | func TestHandleProxyNetworkErrorStill502(t *testing.T) { |
| 818 | proxy := newTestProxy(t) |
| 819 | // Construct a URL that points at no listener: srv.Close before use. |
| 820 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) |
| 821 | dead := srv.URL |
| 822 | srv.Close() |
| 823 | |
| 824 | rec := doForwardProxyRequest(proxy, "GET", dead+"/bucket/anything", http.Header{"Range": []string{"bytes=0-1"}}) |
| 825 | if rec.Code != http.StatusBadGateway { |
| 826 | t.Fatalf("status = %d, want 502 when origin is unreachable", rec.Code) |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | // TestOriginStatusErrorWriteToClampsContentLength locks in the response-framing |
| 831 | // fix: the captured error body is read capped (originErrorBodyCap), so writeTo |
| 832 | // must never forward the origin's declared Content-Length — a misbehaving origin |
| 833 | // that promises more than we captured would otherwise hang the client. (The |
| 834 | // status line and non-length headers still pass through verbatim.) |
| 835 | func TestOriginStatusErrorWriteToClampsContentLength(t *testing.T) { |
| 836 | oe := &originStatusError{ |
| 837 | status: http.StatusForbidden, |
| 838 | headers: http.Header{ |
| 839 | "Content-Length": []string{"104857600"}, // origin claimed 100MB |
| 840 | "Content-Type": []string{"application/xml"}, |