Bugfix - Non-spec behavour in Request.prototype.text
(#2182)
This commit is contained in:
parent
a10d6df430
commit
e0f885e736
3 changed files with 17 additions and 4 deletions
|
@ -556,7 +556,12 @@ mod request {
|
|||
pub async fn text<'js>(&self, ctx: Ctx<'js>, args: Rest<()>) -> Result<String> {
|
||||
let data = self.take_buffer(ctx).await?;
|
||||
|
||||
Ok(String::from_utf8(data.to_vec())?)
|
||||
// Skip UTF-BOM
|
||||
if data.starts_with(&[0xEF, 0xBB, 0xBF]) {
|
||||
Ok(String::from_utf8_lossy(&data[3..]).into_owned())
|
||||
} else {
|
||||
Ok(String::from_utf8_lossy(&data).into_owned())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,12 @@ pub mod response {
|
|||
pub async fn text<'js>(&self, ctx: Ctx<'js>, args: Rest<()>) -> Result<String> {
|
||||
let data = self.take_buffer(ctx).await?;
|
||||
|
||||
Ok(String::from_utf8(data.to_vec())?)
|
||||
// Skip UTF-BOM
|
||||
if data.starts_with(&[0xEF, 0xBB, 0xBF]) {
|
||||
Ok(String::from_utf8_lossy(&data[3..]).into_owned())
|
||||
} else {
|
||||
Ok(String::from_utf8_lossy(&data).into_owned())
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a promise with the response body as text
|
||||
|
|
|
@ -34,8 +34,11 @@ impl<R: Clone + 'static + Send + Sync> ReadableStream<R> {
|
|||
pub fn tee(&mut self) -> (ReadableStream<R>, impl Future<Output = ()>) {
|
||||
// replace the stream with a channel driven by as task.
|
||||
// TODO: figure out how backpressure works in the stream API.
|
||||
let (send_a, recv_a) = channel::bounded::<R>(16);
|
||||
let (send_b, recv_b) = channel::bounded::<R>(16);
|
||||
|
||||
// Unbounded, otherwise when one channel gets awaited it might block forever because the
|
||||
// other channel fills up.
|
||||
let (send_a, recv_a) = channel::unbounded::<R>();
|
||||
let (send_b, recv_b) = channel::unbounded::<R>();
|
||||
let new_stream = Box::pin(ChannelStream(recv_a));
|
||||
let mut old_stream = std::mem::replace(&mut self.0, new_stream);
|
||||
let drive = async move {
|
||||
|
|
Loading…
Reference in a new issue