aboutsummaryrefslogtreecommitdiff
path: root/test/js/web/fetch/fetch.test.ts
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-09-16 21:55:41 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-16 21:55:41 -0700
commit383d5b55d611b62492178eae4833bf3c134de246 (patch)
tree2abd5a03b05939c4c5f80608e5a0a0b5250e9146 /test/js/web/fetch/fetch.test.ts
parent80e1f32ca1236dcf6f7ed559c596afbced0f8f3a (diff)
downloadbun-383d5b55d611b62492178eae4833bf3c134de246.tar.gz
bun-383d5b55d611b62492178eae4833bf3c134de246.tar.zst
bun-383d5b55d611b62492178eae4833bf3c134de246.zip
fix(fetch) handle 100 continue (#5496)
* handle 100 continue * move comment * cleanup * fmt
Diffstat (limited to 'test/js/web/fetch/fetch.test.ts')
-rw-r--r--test/js/web/fetch/fetch.test.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts
index 4ef5d7bba..fc4ce7a18 100644
--- a/test/js/web/fetch/fetch.test.ts
+++ b/test/js/web/fetch/fetch.test.ts
@@ -5,6 +5,7 @@ import { mkfifo } from "mkfifo";
import { tmpdir } from "os";
import { join } from "path";
import { gc, withoutAggressiveGC, gcTick } from "harness";
+import net from "net";
const tmp_dir = mkdtempSync(join(realpathSync(tmpdir()), "fetch.test"));
@@ -1415,3 +1416,62 @@ it("cloned response headers are independent after accessing", () => {
cloned.headers.set("content-type", "text/plain");
expect(response.headers.get("content-type")).toBe("text/html; charset=utf-8");
});
+
+it("should work with http 100 continue", async () => {
+ let server: net.Server | undefined;
+ try {
+ server = net.createServer(socket => {
+ socket.on("data", data => {
+ const lines = data.toString().split("\r\n");
+ for (const line of lines) {
+ if (line.length == 0) {
+ socket.write("HTTP/1.1 100 Continue\r\n\r\n");
+ socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\nHello, World!");
+ break;
+ }
+ }
+ });
+ });
+
+ const { promise: start, resolve } = Promise.withResolvers();
+ server.listen(8080, resolve);
+
+ await start;
+
+ const address = server.address() as net.AddressInfo;
+ const result = await fetch(`http://localhost:${address.port}`).then(r => r.text());
+ expect(result).toBe("Hello, World!");
+ } finally {
+ server?.close();
+ }
+});
+
+it("should work with http 100 continue on the same buffer", async () => {
+ let server: net.Server | undefined;
+ try {
+ server = net.createServer(socket => {
+ socket.on("data", data => {
+ const lines = data.toString().split("\r\n");
+ for (const line of lines) {
+ if (line.length == 0) {
+ socket.write(
+ "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\nHello, World!",
+ );
+ break;
+ }
+ }
+ });
+ });
+
+ const { promise: start, resolve } = Promise.withResolvers();
+ server.listen(8080, resolve);
+
+ await start;
+
+ const address = server.address() as net.AddressInfo;
+ const result = await fetch(`http://localhost:${address.port}`).then(r => r.text());
+ expect(result).toBe("Hello, World!");
+ } finally {
+ server?.close();
+ }
+});