mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
fix: non ascii buffer response in http server (#12728)
This commit is contained in:
parent
0cb81951af
commit
6af916c3f4
5 changed files with 51 additions and 1 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -3263,6 +3263,15 @@ dependencies = [
|
|||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bytes"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.130"
|
||||
|
@ -3315,6 +3324,7 @@ version = "0.17.0"
|
|||
dependencies = [
|
||||
"bencher",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_json",
|
||||
"v8",
|
||||
]
|
||||
|
|
|
@ -999,3 +999,31 @@ unitTest(
|
|||
await Promise.all([server(), client()]);
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { net: true } },
|
||||
async function httpServerRespondNonAsciiUint8Array() {
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
const e = await httpConn.nextRequest();
|
||||
assert(e);
|
||||
const { request, respondWith } = e;
|
||||
assertEquals(request.body, null);
|
||||
await respondWith(
|
||||
new Response(new Uint8Array([128]), {}),
|
||||
);
|
||||
httpConn.close();
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://localhost:4501/");
|
||||
console.log(resp.headers);
|
||||
assertEquals(resp.status, 200);
|
||||
const body = await resp.arrayBuffer();
|
||||
assertEquals(new Uint8Array(body), new Uint8Array([128]));
|
||||
|
||||
await promise;
|
||||
},
|
||||
);
|
||||
|
|
|
@ -11,6 +11,7 @@ description = "Rust to V8 serialization and deserialization"
|
|||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
serde_bytes = "0.11"
|
||||
v8 = "0.34.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -30,8 +30,9 @@ impl<'de> serde::Deserialize<'de> for StringOrBuffer {
|
|||
#[derive(serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum StringOrBufferInner {
|
||||
String(String),
|
||||
#[serde(with = "serde_bytes")]
|
||||
Buffer(Vec<u8>),
|
||||
String(String),
|
||||
}
|
||||
|
||||
impl StringOrBufferInner {
|
||||
|
|
|
@ -173,6 +173,16 @@ fn de_string_or_buffer() {
|
|||
assert_eq!(sob.as_slice(), &[0x68, 0x65, 0x6C, 0x6C, 0x6F]);
|
||||
});
|
||||
|
||||
dedo("new Uint8Array([97])", |scope, v| {
|
||||
let sob: serde_v8::StringOrBuffer = serde_v8::from_v8(scope, v).unwrap();
|
||||
assert_eq!(sob.as_slice(), &[97]);
|
||||
});
|
||||
|
||||
dedo("new Uint8Array([128])", |scope, v| {
|
||||
let sob: serde_v8::StringOrBuffer = serde_v8::from_v8(scope, v).unwrap();
|
||||
assert_eq!(sob.as_slice(), &[128]);
|
||||
});
|
||||
|
||||
dedo(
|
||||
"(Uint8Array.from([0x68, 0x65, 0x6C, 0x6C, 0x6F]))",
|
||||
|scope, v| {
|
||||
|
|
Loading…
Reference in a new issue