Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: friendly exposure of req/res logic for HTTP/2 push promises #2781

Open
ronkorving opened this issue Oct 23, 2015 · 3 comments

Comments

@ronkorving
Copy link

HTTP/2 has a great feature called push promises. It allows you to push files from server to client pro-actively because you know the client will need it. To do this responsibly, you can send along headers that can inform the client about the ETag for example, so the client can abort the file download if it's already in cache. This is all great, but very hard to deal with Express, because I would want to use all the configured Express logic in the push() API that (in my case) node-spdy expose.

In other words, I would love to combine res.sendFile() with res.push() (that node-spdy exposes). This is currently pretty much impossible as far as I can see. If Express could give more access to the internals of how a file would be delivered without actually delivering it (say, provide me with headers and a file stream I could pipe to res.push) that would be a major help. Alternative solutions of course welcome :)

Example spdy-server with Express:

const fs = require('fs');
const config = require('config');
const spdy = require('spdy');
const express = require('express');

const app = express();

const options = {
    key: fs.readFileSync(config.get('server.ssl.key')),
    cert: fs.readFileSync(config.get('server.ssl.cert'))
};

const httpServer = spdy.createServer(options, app);
httpServer.listen(8080);

// a route with a push promise stream:

app.get('/index.html', function (req, res) {
    // index.html is guaranteed to need styles.css
    // if *only* my code could look like this:

    res.push('/styles.css').sendFile('./www/styles.css'));

    res.sendFile('./www/index.html');
});

Unfortunately:

  • Express' sendFile function really sends the file directly on the response stream. I wish I could send it on the push stream.
  • node-spdy doesn't make this easier because of how its push method works (see push docs, cc @indutny).

The glue has to happen somewhere, and I'm not sure where or how. But without any changes to express and/or spdy, it seems impossible to do today.

@jonathanong
Copy link
Member

i have https://github.com/jshttp/spdy-push, but it isn't updated for spdy@2, which supports http2. making it easy to push files is a matter of setting more headers. still wondering if it would be included in node, though...

@ronkorving
Copy link
Author

node-spdy supports push() out of the box, and it seems easy enough to use. The problem is that express does a lot of logic for me to construct good responses to requests. I don't want to have to replicate though (nor have a different middleware solve it in its own way). I want to use express' internal logic, and simple API to deliver content through push. Ideally, doing a push is a one-liner, just like how most operations in Express are one-liners.

@kevinSuttle
Copy link

Is there a label or over-arching Issue mapped to http/2 support? I'd love to have it by default in Express.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants