gateway: an upstream that answers 200 with a web page, with nothing at all, or with JSON that isn't, has failed as a 502 does, so a group asks its next member (#1012, cth123456: Codex on group/medium, agentrouter/deepseek-v4-flash now and then answered 200 text/html; the log said status=200 done=true in=0 out=0 served=null, codex/gpt-6-luna was never asked, and Codex failed with "stream disconnected before completion: stream closed before response.completed") — the candidate loop judged a try by its status alone, and holdWriter passes a 200 that is neither text/event-stream nor application/json straight to the agent, so the page went to Codex as the reply. notAnAPIReply now reads every 2xx (but 204) an upstream gives, in forwardOnce (every relayed and translated request, every API, plugins included) and in the built-in clients' own requests (the ChatGPT backend's /responses, Kiro, Zed, Qoder, Devin, Cursor, Command Code): a text/html reply, a body that begins as a web page whatever its Content-Type, an empty body, or one sent as JSON that doesn't begin with { or [ is turned into the 502 it stands for, with a JSON error saying what came back ("answered 200 OK with a web page (text/html), not an API reply: “Just a moment...”", the firewall hint for a block page). It then fails over, rests a minute and is logged as any 502 before the reply begins does; a provider with nobody after it hands the agent that 502 rather than the page. Only the first bytes are peeked, which a stream waits for anyway; a read that fails is left to the reader, a compressed body and anything else as it came. TestNotAnAPIReplyFailsOver (Chat, Responses and Messages, streamed and not, a member answering a Cloudflare page as text/html, as JSON and as SSE, an empty body as JSON and as SSE, and plain text as JSON; the next member must answer and the log name why) fails without the change in all 36 cases (the page relayed to the agent, or b never asked, or no reason logged) and passes; TestNotAnAPIReplyAlone (a 502 with the reason, logged 502) and TestCodexBackendWebPage (the ChatGPT backend's page reached Codex as a 200) fail without it and pass; TestAPIReplyUntouched keeps JSON after whitespace, SSE with and without a Content-Type, gzip, XML, a 204 and a 404 as they came. -race -count=10 on them; go test -tags nogui ./internal/gateway ./internal/provider, go vet (darwin, windows), gofmt -l, linux and windows (nogui) builds pass. Not tried with the reporter's relay (agentrouter) itself; the page is a Cloudflare challenge's, as the issue has only its Content-Type. docs/subsystems/gateway-routing.md says it.

This commit is contained in:
yetone
2026-10-06 18:26:31 +08:00
parent 82c8735a94
commit b56bfb5a94
11 changed files with 332 additions and 4 deletions
+2 -1
View File
@@ -40,6 +40,7 @@ served by a plugin are in [Provider and plugin ownership](provider-plugins.md).
## Constraints and failure behavior
- A fallback happens only while none of the reply has been sent. An agent never gets half a reply from one upstream and the rest from another.
- A 2xx that can't be an API's answer is the 502 it stands for (`notAnAPIReply`, #1012): a web page (`text/html`, or a body that begins as one: a sign-in page, Cloudflare's challenge), a body with nothing in it, or one sent as JSON that doesn't begin as JSON. Every upstream request goes through it (`forwardOnce`, and the built-in clients' own: the ChatGPT backend's `/responses`, Kiro, Zed, Qoder, Devin, Cursor, Command Code), so it fails over, rests and is logged as a 502 does, its reason naming the page's title. Only the first bytes are peeked, which a stream waits for anyway, and a compressed body is left as it came.
- A streamed request is never left silent while its vendor says nothing. `holdWriter.watch` runs beside each try: past `keepHeldAfter` (15s) it sends a held try's agent the stream's 200 and SSE comments (`keepAlive`), none of the try, so another candidate may still answer in the same stream; once the reply passes, it puts a comment between two of its lines after `keepaliveEvery` of quiet. It stops after `keepaliveLongest` (5 minutes) with nothing from the vendor. A proxy in front such as Cloudflare (125s) otherwise ends the request (#947). Gemini streams get no comments (#934).
- A resting candidate is tried last, never dropped (`restLast`). A lone candidate is tried even while it rests, because there is no other.
- Routing decides who goes first only when nobody has answered the conversation yet. Affinity keeps the answerer while its cache is worth it. Auto mode keeps it across turns while at least `cacheWorth` (1024) tokens were read from the cache and the cache isn't cold (`cacheCold`, 5 minutes).
@@ -54,7 +55,7 @@ served by a plugin are in [Provider and plugin ownership](provider-plugins.md).
## Verification
```sh
go test -tags nogui ./internal/gateway -run 'TestQuiet|TestSilentHeld|TestRotateSpreadsSessions|TestRouting|TestSmartRouting|TestFallback|TestNoFallbackForOtherErrors|TestLastFallbackErrorReachesTheAgent|TestRateLimitedSinksToTheBack|TestGroupRateLimitedSinks|TestAffinity|TestSeveralKeysOnTakeOverFromEachOther|TestSubscriptionAccountsTakeOver|TestGroup|TestTrace|TestImageTool|TestCodexNoCredits|TestClaudeGoesOnMessagesWhereTheRelayHasThem|TestAutoRelaysOnTheClientsOwnAPI|TestSearchOfferedStaysOnTheClientsAPI|TestCodexSearchAnsweredOnResponses|TestAgentEffortOnCursorLocal|TestAzureCompactionWithoutMagpiesReasoning|TestCodexCompact'
go test -tags nogui ./internal/gateway -run 'TestQuiet|TestSilentHeld|TestRotateSpreadsSessions|TestRouting|TestSmartRouting|TestFallback|TestNoFallbackForOtherErrors|TestLastFallbackErrorReachesTheAgent|TestRateLimitedSinksToTheBack|TestGroupRateLimitedSinks|TestAffinity|TestSeveralKeysOnTakeOverFromEachOther|TestSubscriptionAccountsTakeOver|TestGroup|TestTrace|TestImageTool|TestCodexNoCredits|TestClaudeGoesOnMessagesWhereTheRelayHasThem|TestAutoRelaysOnTheClientsOwnAPI|TestSearchOfferedStaysOnTheClientsAPI|TestCodexSearchAnsweredOnResponses|TestAgentEffortOnCursorLocal|TestAzureCompactionWithoutMagpiesReasoning|TestCodexCompact|TestNotAnAPIReply|TestAPIReplyUntouched|TestCodexBackendWebPage'
go test -tags nogui ./internal/provider -run 'TestGroup|TestCodexCreditsSwitch|TestRenewedAccountForgetsItsAllowance|TestNative'
```
+5
View File
@@ -470,6 +470,11 @@ func (s *Server) codexUpstream(w http.ResponseWriter, r *http.Request, rest stri
}
body = b
}
if rest == "/responses" {
// a web page or nothing at all, served 200, is the 502 it stands
// for (#1012)
res = notAnAPIReply(res, "OpenAI: ")
}
defer res.Body.Close()
if base == codexAPIBase && res.StatusCode == http.StatusUnauthorized {
// Codex signed in with an API key OpenAI refuses — often one a
+1
View File
@@ -284,6 +284,7 @@ func (s *Server) askCommandCode(api, key, model string) round {
if err != nil {
return nil, 502, "Command Code: " + err.Error()
}
res = notAnAPIReply(res, "") // a web page served 200 (#1012)
if res.StatusCode/100 != 2 {
b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
res.Body.Close()
+1
View File
@@ -311,6 +311,7 @@ func (s *Server) cursorRun(ctx context.Context, req *Request, model, id, tok, ba
pw.Close()
return nil, 502, "Cursor: " + err.Error()
}
res = notAnAPIReply(res, "") // a web page served 200 (#1012)
if res.StatusCode/100 != 2 {
b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
res.Body.Close()
+1
View File
@@ -86,6 +86,7 @@ func (s *Server) askDevin(home, model string) round {
if err != nil {
return nil, 502, "Devin: " + err.Error()
}
res = notAnAPIReply(res, "") // a web page served 200 (#1012)
if res.StatusCode/100 != 2 {
b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
res.Body.Close()
+3 -2
View File
@@ -2692,8 +2692,9 @@ func (s *Server) forwardOnce(ctx context.Context, p provider.Provider, to provid
if err != nil {
return res, err
}
// Cline's whole replies come in {success, data}
return clineUnwrapped(p, res), nil
// Cline's whole replies come in {success, data}; a web page or
// nothing at all, served 200, is the 502 it stands for (#1012)
return notAnAPIReply(clineUnwrapped(p, res), ""), nil
}
// fromClaudeCode is a request Claude Code sent, by the User-Agent it gives
+5 -1
View File
@@ -122,7 +122,11 @@ func (s *Server) sendKiro(ctx context.Context, auth provider.KiroAuth, body []by
} {
req.Header.Set(k, v)
}
return s.client.Do(req)
res, err := s.client.Do(req)
if err != nil {
return res, err
}
return notAnAPIReply(res, ""), nil // a web page served 200 (#1012)
}
// kiroFailure is the status and message for an error Kiro answered with:
+115
View File
@@ -0,0 +1,115 @@
package gateway
import (
"bufio"
"bytes"
"encoding/json"
"html"
"io"
"net/http"
"regexp"
"strings"
"github.com/yetone/magpie/internal/provider"
)
// notAnAPIReply turns a 2xx reply that can't be a model API's answer into
// the 502 it stands for: a web page (a sign-in page, Cloudflare's
// challenge, a relay's own error page, served 200 text/html), a body that
// is empty, or one sent as JSON that doesn't begin as JSON. Each was taken
// for an answer: relayed to the agent as it came, logged as served with
// nothing in or out, the group's next member never asked — Codex was
// handed a text/html page from a relay and failed with "stream closed
// before response.completed" (#1012). Read as a 502, it is a failure like
// any other before the reply begins: the next key, account or member is
// asked, the try rests as a 502 does, and the log says why. Only the
// reply's first bytes are looked at, which a stream waits for anyway; a
// read that fails is left to the reader, as it was. name prefixes the
// reason, for a caller that doesn't put the provider's name before it.
func notAnAPIReply(res *http.Response, name string) *http.Response {
if res == nil || res.StatusCode < 200 || res.StatusCode >= 300 || res.StatusCode == http.StatusNoContent || res.Body == nil {
return res
}
ct := strings.ToLower(res.Header.Get("Content-Type"))
if strings.HasPrefix(ct, "text/html") {
return asBadGateway(res, name, webPage(res, ct))
}
br := bufio.NewReaderSize(res.Body, 4<<10)
res.Body = readCloser{br, res.Body}
if _, err := br.Peek(1); err == io.EOF {
return asBadGateway(res, name, "answered "+res.Status+" with nothing in it, not an API reply")
} else if err != nil {
return res
}
if ce := res.Header.Get("Content-Encoding"); ce != "" && ce != "identity" {
return res // compressed: its first bytes say nothing of what it is
}
head, _ := br.Peek(br.Buffered())
head = bytes.TrimLeft(head, " \t\r\n\ufeff")
switch {
case htmlStart.Match(head) && !strings.Contains(ct, "xml"):
return asBadGateway(res, name, webPage(res, ct))
case strings.Contains(ct, "json") && len(head) > 0 && head[0] != '{' && head[0] != '[':
b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<10))
return asBadGateway(res, name, "answered "+res.Status+" with a reply that isn't JSON, not an API reply: "+clipRunes(string(bytes.TrimSpace(b)), 200))
}
return res
}
// htmlStart is how a web page begins.
var htmlStart = regexp.MustCompile(`(?i)^<(!doctype\s+html|html[\s>]|head[\s>]|body[\s>])`)
// pageTitle is a web page's title.
var pageTitle = regexp.MustCompile(`(?is)<title[^>]*>(.*?)</title>`)
// webPage says what a page served in place of a reply was, by its title,
// and for a firewall's block page what to do about it.
func webPage(res *http.Response, ct string) string {
b, _ := io.ReadAll(io.LimitReader(res.Body, 64<<10))
if ct == "" {
ct = "no Content-Type"
}
why := "answered " + res.Status + " with a web page (" + strings.TrimSpace(strings.SplitN(ct, ";", 2)[0]) + "), not an API reply"
if m := pageTitle.FindSubmatch(b); m != nil {
if t := strings.Join(strings.Fields(html.UnescapeString(string(m[1]))), " "); t != "" {
why += ": “" + clipRunes(t, 120) + "”"
}
}
if provider.EdgeBlocked(b) {
why += " — " + provider.BlockedHint
}
return why
}
// asBadGateway is res as the 502 it stands for, saying why in an error
// body every reader of one finds its message in.
func asBadGateway(res *http.Response, name, why string) *http.Response {
io.Copy(io.Discard, io.LimitReader(res.Body, 1<<20))
res.Body.Close()
msg := name + why
b, _ := json.Marshal(map[string]any{"error": map[string]any{"message": msg, "type": "bad_gateway"}, "message": msg})
h := res.Header.Clone()
for _, k := range []string{"Content-Type", "Content-Length", "Content-Encoding", "Transfer-Encoding"} {
h.Del(k)
}
h.Set("Content-Type", "application/json")
out := *res
out.StatusCode, out.Status = http.StatusBadGateway, "502 Bad Gateway"
out.Header, out.Body, out.ContentLength = h, io.NopCloser(bytes.NewReader(b)), int64(len(b))
return &out
}
// readCloser reads through a buffer in front of a body, and closes the
// body.
type readCloser struct {
io.Reader
io.Closer
}
// clipRunes is s cut to at most n runes.
func clipRunes(s string, n int) string {
if r := []rune(s); len(r) > n {
return string(r[:n]) + "…"
}
return s
}
+197
View File
@@ -0,0 +1,197 @@
package gateway
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// cloudflarePage is a page a relay serves 200 text/html in place of a
// reply (#1012): Cloudflare's challenge, as it begins.
const cloudflarePage = `<!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><div class="main-wrapper" role="main"><div class="main-content"><noscript>Enable JavaScript and cookies to continue</noscript></div></div></body></html>`
// notAPIOn saves a provider speaking proto at s, its only model m.
func notAPIOn(t *testing.T, id string, proto provider.Protocol, s *scripted) *httptest.Server {
t.Helper()
up := httptest.NewServer(s)
t.Cleanup(up.Close)
p := provider.Provider{ID: id, Name: strings.ToUpper(id), Key: "k", Models: []string{"m"}}
switch proto {
case provider.Anthropic:
p.Anthropic = up.URL
case provider.Responses:
p.Responses = up.URL + "/v1"
default:
p.Chat = up.URL + "/v1"
}
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
return up
}
// goodReply is a whole reply saying "from b", streamed or not, in proto.
func goodReply(proto provider.Protocol, stream bool) reply {
switch {
case proto == provider.Chat && !stream:
return reply{200, "application/json", `{"id":"ok","choices":[{"index":0,"message":{"role":"assistant","content":"from b"},"finish_reason":"stop"}],"usage":{"prompt_tokens":3,"completion_tokens":2}}`}
case proto == provider.Chat:
return reply{200, "text/event-stream", sse(`data: {"id":"ok","choices":[{"index":0,"delta":{"role":"assistant","content":"from b"}}]}`,
`data: {"id":"ok","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":3,"completion_tokens":2}}`,
`data: [DONE]`)}
case proto == provider.Responses && !stream:
return reply{200, "application/json", `{"id":"resp_b","object":"response","status":"completed","model":"m","output":[{"type":"message","id":"msg_b","role":"assistant","status":"completed","content":[{"type":"output_text","text":"from b","annotations":[]}]}],"usage":{"input_tokens":3,"output_tokens":2,"total_tokens":5}}`}
case proto == provider.Responses:
return reply{200, "text/event-stream", sse(`event: response.created`+"\n"+`data: {"type":"response.created","response":{"id":"resp_b","status":"in_progress","output":[]}}`,
`event: response.output_text.delta`+"\n"+`data: {"type":"response.output_text.delta","item_id":"msg_b","output_index":0,"content_index":0,"delta":"from b"}`,
`event: response.completed`+"\n"+`data: {"type":"response.completed","response":{"id":"resp_b","status":"completed","model":"m","output":[{"type":"message","id":"msg_b","role":"assistant","status":"completed","content":[{"type":"output_text","text":"from b","annotations":[]}]}],"usage":{"input_tokens":3,"output_tokens":2,"total_tokens":5}}}`)}
case !stream:
return reply{200, "application/json", `{"id":"msg_b","type":"message","role":"assistant","model":"m","content":[{"type":"text","text":"from b"}],"stop_reason":"end_turn","usage":{"input_tokens":3,"output_tokens":2}}`}
}
return reply{200, "text/event-stream", sse(`event: message_start`+"\n"+`data: {"type":"message_start","message":{"id":"msg_b","role":"assistant","content":[],"usage":{"input_tokens":3}}}`,
`event: content_block_start`+"\n"+`data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}`,
`event: content_block_delta`+"\n"+`data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"from b"}}`,
`event: content_block_stop`+"\n"+`data: {"type":"content_block_stop","index":0}`,
`event: message_delta`+"\n"+`data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":2}}`,
`event: message_stop`+"\n"+`data: {"type":"message_stop"}`)}
}
// askOn sends a request for model in proto, streamed or not.
func askOn(s *Server, proto provider.Protocol, model string, stream bool) *httptest.ResponseRecorder {
st := "false"
if stream {
st = "true"
}
var path, body string
switch proto {
case provider.Responses:
path, body = "/v1/responses", `{"model":"`+model+`","stream":`+st+`,"input":[{"role":"user","content":"hi"}]}`
case provider.Anthropic:
path, body = "/v1/messages", `{"model":"`+model+`","max_tokens":10,"stream":`+st+`,"messages":[{"role":"user","content":"hi"}]}`
default:
path, body = "/v1/chat/completions", `{"model":"`+model+`","stream":`+st+`,"messages":[{"role":"user","content":"hi"}]}`
}
rec := httptest.NewRecorder()
s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
return rec
}
// A group member that answers 200 with a web page, with nothing at all or
// with something sent as JSON that isn't, has failed before its reply
// began: the next member answers, on every API, streamed or not, and the
// log says why the first one didn't (#1012: Codex on group/medium was
// handed a relay's text/html page, logged 200 with nothing in or out).
func TestNotAnAPIReplyFailsOver(t *testing.T) {
bad := []struct {
name string
r reply
why string
}{
{"html", reply{200, "text/html; charset=utf-8", cloudflarePage}, `with a web page (text/html), not an API reply: “Just a moment...”`},
{"html as json", reply{200, "application/json", cloudflarePage}, "with a web page (application/json)"},
{"html as sse", reply{200, "text/event-stream", "\n" + cloudflarePage}, "with a web page (text/event-stream)"},
{"empty", reply{200, "application/json", ""}, "with nothing in it"},
{"empty sse", reply{200, "text/event-stream", ""}, "with nothing in it"},
{"not json", reply{200, "application/json", "upstream connect error or disconnect/reset before headers"}, "with a reply that isn't JSON, not an API reply: upstream connect error"},
}
for _, proto := range []provider.Protocol{provider.Chat, provider.Responses, provider.Anthropic} {
for _, stream := range []bool{false, true} {
for _, x := range bad {
name := string(proto) + "/" + x.name
if stream {
name += "/stream"
}
t.Run(name, func(t *testing.T) {
fresh(t)
a := &scripted{replies: []reply{x.r}}
b := &scripted{replies: []reply{goodReply(proto, stream)}}
notAPIOn(t, "a", proto, a)
notAPIOn(t, "b", proto, b)
if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"a/m", "b/m"}, Routing: provider.Ordered}); err != nil {
t.Fatal(err)
}
s := New()
rec := askOn(s, proto, "group/g", stream)
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "from b") || strings.Contains(rec.Body.String(), "Just a moment") || a.n != 1 || b.n != 1 {
t.Fatalf("%d %s (a %d, b %d)", rec.Code, rec.Body.String(), a.n, b.n)
}
calls := s.Recent()
if len(calls) == 0 || calls[0].Status != 200 || !strings.Contains(calls[0].Fallback, x.why) {
t.Fatalf("log: %+v", calls)
}
})
}
}
}
}
// A provider with nobody after it hands the agent a 502 saying what came
// back, not the page as a reply, and the log has it as the error it was.
func TestNotAnAPIReplyAlone(t *testing.T) {
fresh(t)
a := &scripted{replies: []reply{{200, "text/html; charset=utf-8", cloudflarePage}}}
notAPIOn(t, "a", provider.Responses, a)
s := New()
rec := askOn(s, provider.Responses, "a/m", true)
body := rec.Body.String()
if strings.Contains(body, "<html") || !strings.Contains(body, "A: answered 200 OK with a web page (text/html), not an API reply: “Just a moment...”") {
t.Fatalf("%d %s", rec.Code, body)
}
calls := s.Recent()
if len(calls) == 0 || calls[0].Status != http.StatusBadGateway || !strings.Contains(calls[0].Error, "with a web page") {
t.Fatalf("log: %+v", calls)
}
}
// What an API does answer goes as it came: a reply that begins with
// whitespace, a stream, a compressed body, and a 204.
func TestAPIReplyUntouched(t *testing.T) {
for _, x := range []struct {
ct, ce, body string
code int
}{
{"application/json", "", "\n {\"ok\":true}", 200},
{"text/event-stream", "", "data: {}\n\n", 200},
{"", "", "data: {}\n\n", 200},
{"text/plain", "", "event: x\ndata: {}\n\n", 200},
{"application/json", "gzip", "\x1f\x8b\x08", 200},
{"application/xml", "", "<?xml version=\"1.0\"?><a/>", 200},
{"application/json", "", "", 204},
{"text/html", "", "<html></html>", 404},
} {
res := &http.Response{StatusCode: x.code, Status: http.StatusText(x.code), Header: http.Header{}, Body: io.NopCloser(strings.NewReader(x.body))}
if x.ct != "" {
res.Header.Set("Content-Type", x.ct)
}
if x.ce != "" {
res.Header.Set("Content-Encoding", x.ce)
}
got := notAnAPIReply(res, "")
raw, _ := io.ReadAll(got.Body)
b := string(raw)
if got.StatusCode != x.code || b != x.body {
t.Errorf("%+v: %d %q", x, got.StatusCode, b)
}
}
}
// Codex's own sign-in, relayed to the ChatGPT backend, is told of a web
// page served 200 as the 502 it is, not handed the page as its stream.
func TestCodexBackendWebPage(t *testing.T) {
setup(t, provider.Chat, &fake{t: t})
chatgpt(t, func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
io.WriteString(w, cloudflarePage)
})
req := httptest.NewRequest("POST", CodexPath+"/responses", strings.NewReader(`{"model":"gpt-5.5","stream":true,"input":[]}`))
req.Header.Set("Authorization", "Bearer chatgpt-token")
rec := httptest.NewRecorder()
New().Handler().ServeHTTP(rec, req)
if rec.Code != http.StatusBadGateway || strings.Contains(rec.Body.String(), "<html") || !strings.Contains(rec.Body.String(), "OpenAI: answered 200 OK with a web page") {
t.Fatalf("%d %s", rec.Code, rec.Body)
}
}
+1
View File
@@ -216,6 +216,7 @@ func (s *Server) askQoder(agent, model, user string) round {
if err != nil {
return nil, 502, "Qoder: " + err.Error()
}
res = notAnAPIReply(res, "") // a web page served 200 (#1012)
if res.StatusCode/100 != 2 {
b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
res.Body.Close()
+1
View File
@@ -179,6 +179,7 @@ func (s *Server) askZed(user, model string) round {
}
break
}
res = notAnAPIReply(res, "") // a web page served 200 (#1012)
if res.StatusCode/100 != 2 {
b, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
res.Body.Close()