actix / actix/actix-web

Response Streaming - JavaScript only receiving 1 packet

オープン
#2,910 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
24.8k
フォーク
1.9k
平均マージ
23時間 10分
マージ済み PR(30日)
26

説明

## Rust:
```
use std::convert::Infallible;
use async_stream::stream;
use actix_web::{get, HttpResponse};
use actix_web::web::Bytes;

#[get("/stream")]
pub async fn stream() -> HttpResponse {

HttpResponse::Ok()
.streaming(stream! {
let mut count = 0;
while count < 10 {
yield Ok::<_, Infallible>(Bytes::from(count.to_string()));
thread::sleep(Duration::from_millis(250));
count += 1;
}
})

}
```

## Javascript:
```
async function get_stream() {
const response = await fetch('/stream');
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();

while (true) {
let {value, done} = await reader.read();
if (done) break;
console.log('Received', value);
}

console.log('Response fully received');
}
```

## Expected Behavior:
```
Received 0
Received 1
Received 2
Received 3
Received 4
Received 5
Received 6
Received 7
Received 8
Received 9
stream.js:69 Response fully received
```

## Current Behavior:
```
Received 0123456789
stream.js:69 Response fully received
```

## Context
I'm trying to query a database and send reach row at a time back to the client. I wasn't able to get streaming to properly stream one row at a time. I made this simple example for testing and found that the JavaScript side was receiving all of the data at once.

- I've tested and got the same result in Chrome and Firefox
- Rust Version: rustc 1.64.0 (a55dd71d5 2022-09-19)
- Actix Web Version: 4.2.1
- Server is using rustls for encryption making the web server HTTP2

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。