node-http2 icon indicating copy to clipboard operation
node-http2 copied to clipboard

question: how to close client when done?

Open yoshuawuyts opened this issue 8 years ago • 1 comments

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
})

yoshuawuyts avatar May 27 '16 06:05 yoshuawuyts

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.)

nwgh avatar Aug 02 '16 13:08 nwgh