Skip to content

Commit e836a62

Browse files
authored
Repro for content-length being set (Azure#23332)
1 parent 8714e51 commit e836a62

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

sdk/test-utils/recorder/test/testProxyTests.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT license.
33

44
import { ServiceClient } from "@azure/core-client";
5+
import { createPipelineRequest } from "@azure/core-rest-pipeline";
6+
import { expect } from "chai";
57
import { CustomMatcherOptions, isPlaybackMode, Recorder } from "../src";
68
import { isLiveMode, TestMode } from "../src/utils/utils";
79
import { getTestServerUrl, makeRequestAndVerifyResponse, setTestMode } from "./utils/utils";
@@ -90,6 +92,21 @@ import { getTestServerUrl, makeRequestAndVerifyResponse, setTestMode } from "./u
9092
);
9193
});
9294

95+
describe("does not add a content-length header unnecessarily", () =>
96+
(["GET", "DELETE"] as const).forEach((method) =>
97+
it(`to a ${method} request`, async () => {
98+
await recorder.start({ envSetupForPlayback: {} });
99+
const req = createPipelineRequest({
100+
url: getTestServerUrl() + "/content_length_test",
101+
method,
102+
allowInsecureConnection: isLiveMode(),
103+
});
104+
105+
const rsp = await client.sendRequest(req);
106+
expect(rsp.status).to.be.within(200, 299);
107+
})
108+
));
109+
93110
// Matchers
94111
describe("Matchers", () => {
95112
it("BodilessMatcher", async () => {

sdk/test-utils/recorder/test/utils/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ app.get("/api/sample_uuid_in_header", function (_, res) {
7676
res.send();
7777
});
7878

79+
app.all("/content_length_test", function (req, res) {
80+
if (["GET", "DELETE"].includes(req.method) && req.header("Content-Length")) {
81+
res.status(400).json({ error: "Content-Length header should not be present" });
82+
} else {
83+
res.status(204).send();
84+
}
85+
});
86+
7987
app.listen(port, () => {
8088
console.log(`server started at ${TEST_SERVER_URL}`);
8189
});

0 commit comments

Comments
 (0)