1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00
This commit is contained in:
Satya Rohith 2022-04-03 19:57:00 +05:30
parent 2e4944cc26
commit c60945a7ac
No known key found for this signature in database
GPG key ID: B2705CF40523EB05

View file

@ -652,9 +652,10 @@ async fn op_http_write_headers(
match *stream.accept_encoding.borrow() { match *stream.accept_encoding.borrow() {
Encoding::Gzip => { Encoding::Gzip => {
builder = builder.header("content-encoding", "gzip"); builder = builder.header("content-encoding", "gzip");
*stream.stream_encoder.borrow_mut() = Some(GzEncoder::new(Vec::new(), Compression::new(1))); *stream.stream_encoder.borrow_mut() =
Some(GzEncoder::new(Vec::new(), Compression::new(1)));
} }
_ => {}, _ => {}
} }
// Set the user provided ETag & Vary headers for a streaming response // Set the user provided ETag & Vary headers for a streaming response
@ -709,7 +710,14 @@ async fn op_http_write(
} }
}; };
let bytes = Bytes::copy_from_slice(&buf[..]); let bytes =
if let Some(encoder) = stream.stream_encoder.borrow_mut().as_mut() {
encoder.write_all(&buf.as_ref())?;
encoder.flush()?;
encoder.get_mut().drain(..).collect()
} else {
Bytes::copy_from_slice(&buf[..])
};
match body_tx.send_data(bytes).await { match body_tx.send_data(bytes).await {
Ok(_) => break Ok(()), Ok(_) => break Ok(()),
Err(err) => { Err(err) => {
@ -736,7 +744,9 @@ async fn op_http_shutdown(
.borrow() .borrow()
.resource_table .resource_table
.get::<HttpStreamResource>(rid)?; .get::<HttpStreamResource>(rid)?;
let mut wr = RcRef::map(&stream, |r| &r.wr).borrow_mut().await; let mut wr = RcRef::map(&stream, |r| &r.wr).borrow_mut().await;
wr.write_all(b"").await?;
take(&mut *wr); take(&mut *wr);
Ok(()) Ok(())
} }