feat: refine operations UI and transport limits

This commit is contained in:
hectorzhao
2026-08-13 10:42:59 +08:00
parent fb02cbcf39
commit 67fee21616
34 changed files with 314 additions and 188 deletions
+10 -1
View File
@@ -12,6 +12,8 @@ import (
"time"
)
const maxAPIResponseBodyBytes int64 = 4 * 1024 * 1024
func (s Server) post(ctx context.Context, path string, payload any, result any) error {
client := s.HTTPClient
if client == nil {
@@ -31,10 +33,17 @@ func (s Server) post(ctx context.Context, path string, payload any, result any)
return err
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(io.LimitReader(resp.Body, 64*1024))
// Read one byte beyond the supported boundary so an oversized upstream
// response is reported explicitly. Silently cutting JSON at the boundary
// turns a transport-capacity problem into a misleading syntax error and can
// leave recoverable downstream receipts stuck indefinitely.
responseBody, err := io.ReadAll(io.LimitReader(resp.Body, maxAPIResponseBodyBytes+1))
if err != nil {
return fmt.Errorf("read api response: %w", err)
}
if int64(len(responseBody)) > maxAPIResponseBodyBytes {
return fmt.Errorf("api response exceeds %d-byte limit", maxAPIResponseBodyBytes)
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
detail := strings.TrimSpace(string(responseBody))
if detail == "" {