0

https version:

const fs = require('fs')
const http2 = require('http2')
const server = http2.createSecureServer({
  allowHTTP1: true,
  key: fs.readFileSync('localhost-privkey.pem'),
  cert: fs.readFileSync('localhost-cert.pem'),
})

server.on('stream', (stream, headers) => {
  stream.write('Hello World!\n')
  stream.end()
})
server.listen(443)

running curl -k https://localhost:443 result: Hello World!

http version:

const http2 = require('http2')
const server = http2.createServer({allowHTTP1: true})
server.on('stream', (stream, headers) => {
  stream.write('Hello World!\n')
  stream.end()
})
server.listen(80)

running curl http://localhost:80 result: curl: (1) Received HTTP/0.9 when not allowed

curl version curl 7.88.1 (x86_64-apple-darwin21.6.0) libcurl/7.88.1 (SecureTransport) OpenSSL/1.1.1t zlib/1.2.11 brotli/1.0.9 zstd/1.5.4 libidn2/2.3.4 libssh2/1.10.0 nghttp2/1.52.0 librtmp/2.3 Release-Date: 2023-02-20 Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

node version 18.8

Nir O.
  • 1,563
  • 1
  • 17
  • 26
  • if it is helpful to someone I generated the keys using `openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -keyout localhost-privkey.pem -out localhost-cert.pem` – Nir O. Mar 17 '23 at 21:48
  • Some of the links in [this question](https://stackoverflow.com/questions/61051169/is-tls-mandatory-for-http-2) may be relevant and/or enlightening. – President James K. Polk Mar 19 '23 at 18:15

0 Answers0