diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc1783..0fef79e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Version 1.12.12 - 2024-07-04 +### Fixed + +- Set `content-length` header correctly for OData V4 request in batch mode + ### Added - CI Matrix Test Node 22 diff --git a/src/index.js b/src/index.js index 7e82d32..c1928f8 100644 --- a/src/index.js +++ b/src/index.js @@ -1368,6 +1368,14 @@ function cov2ap(options = {}) { } body = convertRequestBody(body, headers, url, req); } + if (body !== undefined) { + for (const name in headers) { + if (name.toLowerCase() === "content-length") { + headers[name] = Buffer.byteLength(body); + break; + } + } + } return { body, headers }; }, req.contentIdOrder, diff --git a/test/_env/util/batch/Batch-POST.txt b/test/_env/util/batch/Batch-POST.txt index 2d04d0e..ffc472e 100644 --- a/test/_env/util/batch/Batch-POST.txt +++ b/test/_env/util/batch/Batch-POST.txt @@ -4,8 +4,9 @@ Content-ID: 1 POST Header HTTP/1.1 Content-Type: application/json +Content-Length: 39 -{"name":"Test – ABC"} +{"name":"Test – ABC","__metadata":{}} --boundary Content-Type: application/http