-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix regression on http2-wrapper caused by node.js compatibility impro…
…vements on net (#15318)
- Loading branch information
1 parent
82cb82d
commit c04a2d1
Showing
7 changed files
with
160 additions
and
48 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
Binary file not shown.
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
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
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,89 @@ | ||
import { test, expect } from "bun:test"; | ||
import { tls } from "harness"; | ||
import http2Wrapper from "http2-wrapper"; | ||
import type { AutoRequestOptions } from "http2-wrapper"; | ||
import http from "http"; | ||
|
||
async function doRequest(options: AutoRequestOptions) { | ||
const { promise, resolve, reject } = Promise.withResolvers(); | ||
const request = await http2Wrapper.auto(options, (response: http.IncomingMessage) => { | ||
if (response.statusCode !== 200) { | ||
return reject(new Error(`expected status code 200 rejected: ${response.statusCode}`)); | ||
} | ||
|
||
const body: Array<Buffer> = []; | ||
response.on("error", reject); | ||
response.on("data", (chunk: Buffer) => body.push(chunk)); | ||
response.on("end", () => { | ||
resolve(Buffer.concat(body).toString()); | ||
}); | ||
}); | ||
|
||
request.on("error", reject); | ||
|
||
request.end("123456"); | ||
const body = (await promise) as string; | ||
expect(body).toBeString(); | ||
const parsed = JSON.parse(body); | ||
expect(parsed.data).toBe("123456"); | ||
} | ||
|
||
test("should allow http/1.1 when using http2-wrapper", async () => { | ||
{ | ||
using server = Bun.serve({ | ||
async fetch(req) { | ||
return new Response( | ||
JSON.stringify({ | ||
data: await req.text(), | ||
}), | ||
{ | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
}, | ||
); | ||
}, | ||
}); | ||
|
||
await doRequest({ | ||
host: "localhost", | ||
port: server.port, | ||
protocol: "http:", | ||
path: "/post", | ||
method: "POST", | ||
headers: { | ||
"content-length": 6, | ||
}, | ||
}); | ||
} | ||
|
||
{ | ||
using server = Bun.serve({ | ||
tls, | ||
hostname: "localhost", | ||
async fetch(req) { | ||
return new Response( | ||
JSON.stringify({ | ||
data: await req.text(), | ||
}), | ||
{ | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
}, | ||
); | ||
}, | ||
}); | ||
await doRequest({ | ||
host: "localhost", | ||
port: server.port, | ||
protocol: "https:", | ||
path: "/post", | ||
method: "POST", | ||
ca: tls.cert, | ||
headers: { | ||
"content-length": 6, | ||
}, | ||
}); | ||
} | ||
}); |
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,7 @@ | ||
{ | ||
"name": "http2-wrapper-test", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"http2-wrapper": "2.2.1" | ||
} | ||
} |
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