Skip to content

Instantly share code, notes, and snippets.

@devsnek
Created June 6, 2021 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devsnek/9a047c13d4357a47721c2adc19a7704c to your computer and use it in GitHub Desktop.
Save devsnek/9a047c13d4357a47721c2adc19a7704c to your computer and use it in GitHub Desktop.
'use strict';
const http = require('http');
const http2 = require('http2');
const req = http.get('http://nghttp2.org/httpbin/get', {
headers: {
'Connection': 'Upgrade, HTTP2-Settings',
'Upgrade': 'h2c',
'HTTP2-Settings': http2.getPackedSettings().toString('base64'),
},
});
req.once('upgrade', (r, socket, h) => {
const session = http2.connect('http://nghttp2.org', {
createConnection: () => socket,
});
const req = session.request({
':path': '/httpbin/get',
':method': 'GET',
});
req.once('response', console.log);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment