zostay / RakuWAPI

The Web API for Raku (RakuWAPI)
Artistic License 2.0
24 stars 5 forks source link

How can a P6SGI application push? #19

Closed zostay closed 9 years ago

zostay commented 9 years ago

Within the context of a WebSocket or HTTP/2 connection, a P6SGI application could push content back to the client without requiring the client to initiate a request. WebSocket does this using a chat-like service and HTTP/2 does this with a sort of false request (PUSH_PROMISE) initiated by the server. However, in both cases, the client still initiates the connection to the server, but it holds that connection open until either the server or the client terminate the connection.

We need some sort of meta-application API that allows an application to be notified when a client is available to the server for this kind of push-processing and allow that API to initiate communication back to the client.

zostay commented 9 years ago

Okay, so my initial understanding of server push was flawed. I was under the impression that a server could push data arbitrarily, but this does not appear to be the case. Instead, the push is associated with an existing request. So, if the server knows there are 20 images linked in an HTML file, it can go ahead and suggest those or it could go ahead and initiate sending a redirected document for an initial redirect response.

I'm not sure an application needs to be able to arbitrarily initiate a push or that such might be possible within the existing general API.

muraiki commented 9 years ago

Whoops, I meant to comment on this when you first posted it. Yes, you can't quite use HTTP2 like you would use a WebSocket. There is a draft for WebSocket over HTTP2: http://tools.ietf.org/html/draft-hirano-httpbis-websocket-over-http2-00

zostay commented 9 years ago

Interesting. My first thought was to wonder why you'd bother since WebSocket already exists, but I suppose by combining HTTP/2 you could setup WebSockets as streams within the existing persistent connection and stream both regular HTTP requests and WebSockets over the same connection, whereas if you use HTTP/2 and WebSockets now, you'd need at least 2 connections. Something to keep in mind, but if we can work out the API for handling arbitrary messages from a WebSocket, handling the same over HTTP/2 should (in theory) be no different to the application.

zostay commented 9 years ago

I'm resolving this with the HTTP/2 protocol documentation requiring a p6sgix.h2.push-promise stream. I conveniently left out the details of how this will be defined for now as I still need to do more research (i.e., I plan to figure that out when I implement it in Smack, but I believe this is enough.