[Feature Request] Support Keep-Alive Connections
- Dominant language
- TypeScript
- Stars
- 40k
- Forks
- 2.4k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 61
Description
It seems both the response preview in the UI and the response hook in the plugin do not complete until the response fully ends. This is a problem for long-polling apis such as the twitter real-time stream api.
The timeline seems to know about the connection and even the chunk size.
```
> GET /1.1/statuses/filter.json?track=[redacted] HTTP/2
> Host: stream.twitter.com
> User-Agent: insomnia/7.0.5
> Content-Type: application/json
> Connection: Keep-Alive
> Keep-Alive: timeout=5, max=100
> Authorization: OAuth [redacted]
> Accept: */*
< HTTP/2 200
< content-type: application/json
< date: Thu, 12 Dec 2019 00:01:19 GMT
< server: tsa_b
< strict-transport-security: max-age=631138519
< x-connection-hash: 8d4dc029176169d4e38592fda69bfb1c
< x-response-time: 27
* Received 2 B chunk
* Received 4 KB chunk
* Received 2019 B chunk
* Received 4 KB chunk
* Received 2003 B chunk
* Received 2.8 KB chunk
* Received 2 B chunk
```
I created a plugin at first to try to add the functionality, but it turns out the the response hook doesn't fire until the response completes, which is never.
```js
module.exports.responseHooks = [
context => {
const output = `${os.homedir()}/stream.json`;
const stream = context.response.getBodyStream();
stream.pipe(fs.createWriteStream(output));
}
];
```
At the very least, you could abort the keep-alive session after X seconds, then complete the response.
Contributor guide
Research direction
The issue names the response preview, response hook, timeline, and context.response.getBodyStream(); begin by tracing where the hook waits for completion and how chunk sizes are surfaced. Use the long-polling example to verify the expected behavior and the proposed timeout or abort path. Done means ongoing responses can be consumed by both the preview and hook, with a defined way to finish the response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, frontend, networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100