-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node-http-handler): skip sending body without waiting for a timeo…
…ut on response, if "expect" request header with "100-continue" is provided (#1459) * fix(node-http-handler): skip sending body without waiting for a timeout on response, if "expect" request header with "100-continue" is provided * fix(node-http-handler): skip sending body without waiting for a timeout on response, if "expect" request header with "100-continue" is provided * add unit tests --------- Co-authored-by: George Fu <[email protected]>
- Loading branch information
1 parent
430021a
commit f4e1a45
Showing
3 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@smithy/node-http-handler": patch | ||
--- | ||
|
||
skip sending body without waiting for a timeout on response, if "expect" request header with "100-continue" is provided |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import EventEmitter from "events"; | ||
import { describe, expect, test as it, vi } from "vitest"; | ||
|
||
import { writeRequestBody } from "./write-request-body"; | ||
|
||
describe(writeRequestBody.name, () => { | ||
it("should wait for the continue event if request has expect=100-continue", async () => { | ||
const httpRequest = Object.assign(new EventEmitter(), { | ||
end: vi.fn(), | ||
}) as any; | ||
const request = { | ||
headers: { | ||
expect: "100-continue", | ||
}, | ||
body: Buffer.from("abcd"), | ||
method: "GET", | ||
hostname: "", | ||
protocol: "https:", | ||
path: "/", | ||
}; | ||
let done: (value?: unknown) => void; | ||
const promise = new Promise((r) => (done = r)); | ||
setTimeout(async () => { | ||
httpRequest.emit("continue", {}); | ||
done(); | ||
}, 25); | ||
await writeRequestBody(httpRequest, request); | ||
expect(httpRequest.end).toHaveBeenCalled(); | ||
await promise; | ||
}); | ||
it( | ||
"should not send the body if the request is expect=100-continue" + | ||
"but a response is received before the continue event", | ||
async () => { | ||
const httpRequest = Object.assign(new EventEmitter(), { | ||
end: vi.fn(), | ||
}) as any; | ||
const request = { | ||
headers: { | ||
expect: "100-continue", | ||
}, | ||
body: { | ||
pipe: vi.fn(), | ||
}, | ||
method: "GET", | ||
hostname: "", | ||
protocol: "https:", | ||
path: "/", | ||
}; | ||
let done: (value?: unknown) => void; | ||
const promise = new Promise((r) => (done = r)); | ||
setTimeout(() => { | ||
httpRequest.emit("response", {}); | ||
done(); | ||
}, 25); | ||
await writeRequestBody(httpRequest, request); | ||
expect(request.body.pipe).not.toHaveBeenCalled(); | ||
expect(httpRequest.end).not.toHaveBeenCalled(); | ||
await promise; | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters