node-http2
node-http2 copied to clipboard
question: how to close client when done?
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
})
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.)