From 32f9699007ecec39a79f3428bd97a4438ce1db9a Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 4 May 2026 07:55:21 +0000 Subject: [PATCH] fix: content-length = -1 instead of 0 when unknown --- internal/jshttp/request.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/jshttp/request.go b/internal/jshttp/request.go index a0c7797..2fc4db9 100644 --- a/internal/jshttp/request.go +++ b/internal/jshttp/request.go @@ -30,13 +30,17 @@ func ToRequest(req js.Value) (*http.Request, error) { } header := ToHeader(req.Get("headers")) - // ignore err - contentLength, _ := strconv.ParseInt(header.Get("Content-Length"), 10, 64) + contentLength, clErr := strconv.ParseInt(header.Get("Content-Length"), 10, 64) + bodyVal := req.Get("body") + if clErr != nil && !bodyVal.IsNull() && !bodyVal.IsUndefined() { + contentLength = -1 + } + return &http.Request{ Method: req.Get("method").String(), URL: reqUrl, Header: header, - Body: ToBody(req.Get("body")), + Body: ToBody(bodyVal), ContentLength: contentLength, TransferEncoding: strings.Split(header.Get("Transfer-Encoding"), ","), Host: header.Get("Host"),