npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@httptoolkit/httpolyglot

v3.0.1

Published

Serve http and https connections over the same port with node.js

Readme

Httpolyglot Build Status Available on NPM

Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S)

A module for serving HTTP, HTTPS and HTTP/2 connections, all over the same port.

Forked from the original httpolyglot to fix various issues required for HTTP Toolkit, including:

  • Support for HTTP/2
  • Fixing tlsClientError: https://github.com/mscdex/httpolyglot/pull/11
  • Include initially sniffed bytes aren't lost in subsequent clientError events (https://github.com/mscdex/httpolyglot/issues/13)
  • Dropping support for very old versions of Node (and thereby simplifying the code somewhat)
  • Converting to TypeScript
  • Event subscription support (subscribe to server.on(x, ...) to hear about x from all internal servers - HTTP/2, HTTP/1, TLS and net)
  • Adding support for SOCKS connections
  • Adding support for custom handling of unknown protocols

Requirements

Install

npm install @httptoolkit/httpolyglot

Examples

  • Simple usage:
import * as httpolyglot from '@httptoolkit/httpolyglot';
import * as fs from 'fs';

httpolyglot.createServer({
  tls: {
    key: fs.readFileSync('server.key'),
    cert: fs.readFileSync('server.crt')
  }
}, function(req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end((req.socket.encrypted ? 'HTTPS' : 'HTTP') + ' Connection!');
}).listen(9000, 'localhost', function() {
  console.log('httpolyglot server listening on port 9000');
  // visit http://localhost:9000 and https://localhost:9000 in your browser ...
});
  • Simple redirect of all http connections to https:
import * as httpolyglot from '@httptoolkit/httpolyglot';
import * as fs from 'fs';

httpolyglot.createServer({
  tls: {
    key: fs.readFileSync('server.key'),
    cert: fs.readFileSync('server.crt')
  }
}, function(req, res) {
  if (!req.socket.encrypted) {
    res.writeHead(301, { 'Location': 'https://localhost:9000' });
    return res.end();
  }
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Welcome, HTTPS user!');
}).listen(9000, 'localhost', function() {
  console.log('httpolyglot server listening on port 9000');
  // visit http://localhost:9000 and https://localhost:9000 in your browser ...
});

API

  • createServer([< object >config, ]< function >requestListener) - Server - Creates and returns a new Server instance.

If no config is provided, this server handles HTTP/1 & HTTP/2 in plain text on the same port.

If a config is provided, it can contain:

  • tls - Either TLS configuration options for tls.createServer, or an existing tls.Server instance. Setting this option enables TLS, so that HTTP/1 & HTTP/2 are accepted over both plain-text & encrypted (HTTPS) connections on the same port. If configuration options are provided, Httpolyglot will handle TLS automatically. If a server is provided, the connection will be passed to it (by emitting the connection event) and Httpolyglot will wait for the server to emit secureConnection (the default TLS server event) to handle the content within.
  • socks - A net.Server instance, which will handle any incoming SOCKS connections. If this is provided, SOCKSv4 and SOCKSv5 connections will be emitted as connection events on this server. If not, all SOCKS connections will be treated like any other unknown protocol.
  • unknownProtocol - A net.Server instance, which will handle any unknown protocols. If this is provided, unrecognized protocols will be emitted as connection events on this server. If it's not provided, these connections will be passed to the HTTP server by default, which will typically result in a clientError event and a 400 HTTP response being sent to the client.

How it Works

TLS, HTTP, HTTP/2, SOCKS and other connections are easy to distinguish based on the first byte sent by clients trying to connect. See this comment for more information.