spdy-http2 / spdy-transport

SPDY v2, v3, v3.1 and HTTP2 transport implementation for node.js
101 stars 37 forks source link

be a duplex stream #14

Open mafintosh opened 9 years ago

mafintosh commented 9 years ago

Hi. Great work on getting the spdy protocol working :tada:

Instead of having the transport.connection.create accept a stream it would be nice if it instead just returned a duplex stream that you could pipe your transport to/from.

var spdy = transport.connection.create()
var socket = net.connect(...)

var req = spdy.request(...)
spdy.on('stream', function (stream) {
  ...
})

socket.pipe(spdy).pipe(socket)

This makes it easier compose stream pipelines with spdy. For example using stdin/stdout

process.stdin.pipe(spdy).pipe(process.stdout)

Or using an encrypted stream

transport.pipe(decryptor).pipe(spdy).pipe(encryptor).pipe(transport)

If this is something you'd be interested in adding I'd be happy to help out with a PR

indutny commented 9 years ago

I think it might be very interesting, indeed!

Thanks for the proposal!

jbenet commented 9 years ago

/seconded, i think this api would be very nice.

daviddias commented 9 years ago

Hey @mafintosh did you manage to get this working? I'm in the middle of some ipfs-swarm refactoring and this would sweet to make the API simpler. In the process, the multistream-select would get more 'streamy' too