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