molnarg / node-http2

An HTTP/2 client and server implementation for node.js
MIT License
1.79k stars 187 forks source link

question: how to close client when done? #203

Open yoshuawuyts opened 8 years ago

yoshuawuyts commented 8 years ago

How do I close the client when done? process.exit() terminates Node, which is undesirable. Thanks a lot!

#!/usr/bin/env node

const xtend = require('xtend/mutable')
const http2 = require('http2')
const url = require('url')
const fs = require('fs')

const serviceKey = fs.readFileSync('./certs/service.key')
const certificate = fs.readFileSync('./certs/certificate.pem')

const opts = url.parse('https://localhost:1337/')
xtend(opts, { key: serviceKey, ca: certificate })
const request = http2.get(opts)

request.on('response', function (res) {
  res.pipe(process.stdout)
  // we're all done - We'd like to close the client now
})
nwgh commented 7 years ago

Why do you want to close the client? The entire point of http/2 is that you don't have to keep opening connections. (Not saying having an option to close is a bad idea, but I'm wondering why you can't just let the connection time out.)