cloudflare / cloudflare/cloudflared
🐛Streaming requests with the fetch API doesn't work.
- Dominant language
- Go
- Stars
- 15.6k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Streaming requests with the fetch API doesn't work when using Cloudflare Tunnel.
**To Reproduce**
Steps to reproduce the behavior:
1. Run `./cloudflared tunnel --hello-world --protocol=http2`
2. Open the quick Tunnel URL `https://xxx.trycloudflare.com` in Google Chrome
3. Run this code in the Console
```javascript
function wait(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
const stream = new ReadableStream({
async start(controller) {
await wait(1000);
controller.enqueue('This ');
await wait(1000);
controller.enqueue('is ');
await wait(1000);
controller.enqueue('a ');
await wait(1000);
controller.enqueue('slow ');
await wait(1000);
controller.enqueue('request.');
controller.close();
},
}).pipeThrough(new TextEncoderStream());
fetch("/", {
method: 'POST',
headers: {'Content-Type': 'text/plain'},
body: stream,
duplex: 'half',
});
```
4. Using Wireshark we can see the cloudflared received the whole request in one DATA frame.
```
HyperText Transfer Protocol 2
Stream: DATA, Stream ID: 63, Length 23
Length: 23
Type: DATA (0)
Flags: 0x01, End Stream
0... .... .... .... .... .... .... .... = Reserved: 0x0
.000 0000 0000 0000 0000 0000 0011 1111 = Stream Identifier: 63
[Pad Length: 0]
Data: 54686973206973206120736c6f7720726571756573742e
Line-based text data: text/plain (1 lines)
This is a slow request.
```
**Expected behavior**
cloudflared should receive 5 DATA frames.
**Environment and versions**
- OS: Linux debian
- Architecture: amd64
- Version: 2024.12.2
Contributor guide
Assessment
This issue has not been assessed yet.