Thursday, 27 April 2017

Unable to do http2 push

I'm just testing out http2 push using the spdy library. My script is as below:

var fs = require("fs");
var spdy = require("spdy");

var options = {
    key: fs.readFileSync(__dirname + "/localhost.key"),
    cert: fs.readFileSync(__dirname + "/localhost.crt"),
    spdy: {
        protocols: ["h2"]
    }
};

var server = spdy.createServer(options, function(req, res){
    if(req.url !== '/') {
        res.writeHead(404);
        res.end();
        return;
    }

    res.writeHead(200);
    var stream = res.push("/stream1234", {
        status: 200,
        method: "GET",
        request: { accept: "*/*" },
        response: {
            "content-type": "text/plain"
        }
    });

    stream.end('[{"foo":"bar"}]');
    res.end("<h1>Hello world</h1>");
});
server.listen(8084);

However, when I open by browser and look at the network tab expecting to see "/stream1234" listed, it is not listed. I can confirm that the res.push function does exist, so I know it is a http2 response. Any ideas what I'm doing wrong here?



via Matthew Phillips

No comments:

Post a Comment