Skip to content

Commit 00711f8

Browse files
committed
[No Bug] Fix gzipped ping upload for Node.
This additionally adds the related test coverage.
1 parent c44b728 commit 00711f8

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* [#1271](https://github.com/mozilla/glean.js/pull/1271): BUGFIX: Fix pings validation function when scanning pings database on initialize.
66
* This bug was preventing pings that contained custom headers from being successfully validated and enqueued on initialize.
7+
* [#](): BUGFIX: Fix uploading gzip-compressed pings in Node.
78

89
# v1.0.0 (2022-03-17)
910

glean/src/platform/node/uploader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import https from "https";
66
import http from "http";
77

8+
import { isString } from "../../core/utils.js";
89
import log, { LoggingLevel } from "../../core/log.js";
910
import Uploader, {
1011
UploadResult,
@@ -55,7 +56,7 @@ class NodeUploader extends Uploader {
5556
});
5657

5758
// Finish sending the request.
58-
request.end(body);
59+
request.end(isString(body) ? body : Buffer.from(body.buffer));
5960
});
6061
}
6162
}

glean/tests/unit/platform/node/uploader.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ describe("Uploader/Node", function () {
1717

1818
it("returns the correct status for successful requests", async function () {
1919
for (const status of [200, 400, 500]) {
20-
nock(MOCK_ENDPOINT).post(/./i).reply(status);
21-
22-
const response = NodeUploader.post(MOCK_ENDPOINT, "");
23-
const expectedResponse = new UploadResult(UploadResultStatus.Success, status);
24-
assert.deepStrictEqual(
25-
await response,
26-
expectedResponse
27-
);
20+
// We support both plain text and binary payloads (for gzipped content)
21+
// so test them both.
22+
for (const body of ["", new Uint8Array()]) {
23+
nock(MOCK_ENDPOINT).post(/./i).reply(status);
24+
25+
const response = NodeUploader.post(MOCK_ENDPOINT, body);
26+
const expectedResponse = new UploadResult(UploadResultStatus.Success, status);
27+
assert.deepStrictEqual(
28+
await response,
29+
expectedResponse
30+
);
31+
}
2832
}
2933
});
3034

0 commit comments

Comments
 (0)