6 ms·
I didn't know that HTTP2 supports streaming data. How is this done? It is not a websocket connection. /clockstream streams the current time every second An
by nodesocket 12y ago
I didn't know that HTTP2 supports streaming data. How is this done? It is not a websocket connection.
/clockstream streams the current time every second
And why does it require ~1KB of junk to force browsers to start rendering immediately?
- shurcooL 12y agoSome browsers will try to guess the content type from first few bytes, so they won't start showing anything until enough bytes have been received. Well behaved browsers should not do that if Content-Type header is set.
- pests 12y agoI thought this has something to do with browsers returning their own internal 404 page if the content was less than 1kb? Something to do with that being the max size of error pages on old webservers, which browsers wanted to replace.
- donatj 12y agoYou can do this with HTTP1 actually. Its how motion jpeg works. I've actually got a little mjpeg php script here - https://github.com/donatj/mjpeg-php/blob/master/mjpeg.php https://github.com/donatj/mjpeg-php/blob/master/mjpeg.php Just flush every frame and you're golden. I've also seen simple dashboards that do this, displaying one line at a time as data comes in, simply never closing the connection.
- staunch 12y agoThe code might help: https://github.com/bradfitz/http2/blob/master/h2demo/h2demo.go#L171 https://github.com/bradfitz/http2/blob/master/h2demo/h2demo....
- rakoo 12y ago> I didn't know that HTTP2 supports streaming data It's not specific to HTTP2, and is in fact possible since the server doesn't send a Content-Length so the client doesn't know when the server is done. Think of it not as streaming, but as a really slow and consistent huge response. HTTP2 just makes it smoother (remember: HTTP2 doesn't change semantics, it only changes how things are represented on the wire) Now, the way the demo server uses that is a bit rough; there is a specification for that in the form of Server-Sent events (https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events https://developer.mozilla.org/en-US/docs/Server-sent_events/...).