diff options
Diffstat (limited to 'libpanto/src/provider_openai_chat.zig')
| -rw-r--r-- | libpanto/src/provider_openai_chat.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libpanto/src/provider_openai_chat.zig b/libpanto/src/provider_openai_chat.zig index 8319d9d..5152d3e 100644 --- a/libpanto/src/provider_openai_chat.zig +++ b/libpanto/src/provider_openai_chat.zig @@ -140,6 +140,10 @@ pub const OpenAIChatRequest = struct { rr.response = try rr.req.receiveHead(&redirect_buf); if (@intFromEnum(rr.response.head.status) >= 400) { + // `head.bytes` (which `iterateHeaders` walks) points into the + // connection read buffer and is invalidated the moment the body + // stream is initialized below. Capture Retry-After first. + const retry_after_ms = provider_mod.retryAfterFromHead(rr.response.head); // Drain body for diagnostics. const body_reader = rr.response.reader(&rr.transfer_buf); var err_buf: std.ArrayList(u8) = .empty; @@ -159,7 +163,7 @@ pub const OpenAIChatRequest = struct { const classified = provider_mod.classifyHttpStatus(status, err_buf.items); if (self.diag) |d| { d.status_code = status; - d.retry_after_ms = provider_mod.retryAfterFromHead(rr.response.head); + d.retry_after_ms = retry_after_ms; } return classified; } |
