spdy-http2 / node-spdy

SPDY server on Node.js
2.8k stars 196 forks source link

Examples working with plain = true and ssl = false #197

Closed nodeIntegrator closed 8 years ago

nodeIntegrator commented 9 years ago

So, I have been trying to get the examples to work, but in plain mode, by making the below changes.

var options = {
  //key: fs.readFileSync('keys/spdy-key.pem'),
  //cert: fs.readFileSync('keys/spdy-cert.pem'),
  //ca: fs.readFileSync('keys/spdy-csr.pem'),
  version: 'spdy/3.1',
  plain: true,
  ssl: false
};

I test it using spdycat -nv -3 [my url], and it works fine.

But if I try to use it with any browser or the okHttp java library, it crashes the app with this:

  res.push('/' + Math.random() + '.txt', {
      ^
TypeError: Object #<ServerResponse> has no method 'push'
    at Server.<anonymous> (/home/user/node-spdy/examples/hello_world/app.js:25:7)
    at Server.EventEmitter.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2108:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
    at Socket.socket.ondata (http.js:1966:22)
    at TCP.onread (net.js:525:27)

I have tried several versions of the library and similar examples, none work.

I feel like I am missing something fundamental about this module and perhaps the protocol, but I worry about using the module if it is this brittle (someone with the wrong browser crashing the server).

Obviously, the examples aren't exactly production code, and I don't mean to be too sharp with my criticism, but any available insight is greatly appreciated.

indutny commented 9 years ago

I'm afraid res.push is available only for SPDY streams, so if browsers does request to a plain-mode server - it'll use HTTP. Thus, there won't be a res.push.

Guess, this is an example bug. I'd appreciate if someone will fix it ;)

nodeIntegrator commented 9 years ago

So, as a newbie to this, maybe I am going about this the wrong way... What is the right configuration for doing SSL termination separately (using NGINX, stud, apache, etc.) where I unwrap HTTPS and proxy to node-spdy?

indutny commented 9 years ago

@nodeIntegrator you need to advertise SPDY support in NPN if you want to use plain mode. AFAIK, stud does not support it out-of-the-box. However we added support to it at Voxer:

You could also consider giving a try to: https://github.com/indutny/bud, which does support it quite well.

nodeIntegrator commented 9 years ago

Ahhh, it all makes sense now. I hadn't put together the idea that the NPN support would need to be on the SSL termination side (though it is obvious now). Thanks for the clarification.

I will give those options a shot.