mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
fix issue with null bodies, move npm package to client/
This commit is contained in:
parent
4edf27198a
commit
75c48ccded
8 changed files with 79 additions and 75 deletions
|
@ -352,42 +352,48 @@ impl EpoxyClient {
|
|||
.status(resp.status().as_u16())
|
||||
.status_text(resp.status().canonical_reason().unwrap_or_default());
|
||||
|
||||
let compression = match resp
|
||||
.headers()
|
||||
.get("Content-Encoding")
|
||||
.and_then(|val| val.to_str().ok())
|
||||
.unwrap_or_default()
|
||||
{
|
||||
"gzip" => Some(EpxCompression::Gzip),
|
||||
"br" => Some(EpxCompression::Brotli),
|
||||
_ => None,
|
||||
};
|
||||
let stream = if !utils::is_null_body(resp.status().as_u16()) {
|
||||
let compression = match resp
|
||||
.headers()
|
||||
.get("Content-Encoding")
|
||||
.and_then(|val| val.to_str().ok())
|
||||
.unwrap_or_default()
|
||||
{
|
||||
"gzip" => Some(EpxCompression::Gzip),
|
||||
"br" => Some(EpxCompression::Brotli),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let incoming_body = IncomingBody::new(resp.into_body());
|
||||
let decompressed_body = match compression {
|
||||
Some(alg) => match alg {
|
||||
EpxCompression::Gzip => Either::Left(Either::Left(ReaderStream::new(
|
||||
async_comp::GzipDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
EpxCompression::Brotli => Either::Left(Either::Right(ReaderStream::new(
|
||||
async_comp::BrotliDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
},
|
||||
None => Either::Right(incoming_body),
|
||||
};
|
||||
let stream = wasm_streams::ReadableStream::from_stream(decompressed_body.map(|x| {
|
||||
Ok(Uint8Array::from(
|
||||
x.replace_err_jv("Failed to get frame from response")?
|
||||
.as_ref(),
|
||||
let incoming_body = IncomingBody::new(resp.into_body());
|
||||
|
||||
let decompressed_body = match compression {
|
||||
Some(alg) => match alg {
|
||||
EpxCompression::Gzip => Either::Left(Either::Left(ReaderStream::new(
|
||||
async_comp::GzipDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
EpxCompression::Brotli => Either::Left(Either::Right(ReaderStream::new(
|
||||
async_comp::BrotliDecoder::new(StreamReader::new(incoming_body)),
|
||||
))),
|
||||
},
|
||||
None => Either::Right(incoming_body),
|
||||
};
|
||||
Some(
|
||||
wasm_streams::ReadableStream::from_stream(decompressed_body.map(|x| {
|
||||
Ok(Uint8Array::from(
|
||||
x.replace_err_jv("Failed to get frame from response")?
|
||||
.as_ref(),
|
||||
)
|
||||
.into())
|
||||
}))
|
||||
.into_raw(),
|
||||
)
|
||||
.into())
|
||||
}));
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let resp = web_sys::Response::new_with_opt_readable_stream_and_init(
|
||||
Some(&stream.into_raw()),
|
||||
&respinit,
|
||||
)
|
||||
.replace_err("Failed to make response")?;
|
||||
let resp =
|
||||
web_sys::Response::new_with_opt_readable_stream_and_init(stream.as_ref(), &respinit)
|
||||
.replace_err("Failed to make response")?;
|
||||
|
||||
Object::define_property(
|
||||
&resp,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue