{"id":19738274,"url":"https://github.com/httptoolkit/httpolyglot","last_synced_at":"2025-04-07T15:07:57.994Z","repository":{"id":42690974,"uuid":"186835245","full_name":"httptoolkit/httpolyglot","owner":"httptoolkit","description":"Serve http and https connections over the same port with node.js","archived":false,"fork":false,"pushed_at":"2025-03-31T12:45:20.000Z","size":79,"stargazers_count":17,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T13:16:44.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mscdex/httpolyglot","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/httptoolkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-15T13:44:59.000Z","updated_at":"2025-03-31T12:45:24.000Z","dependencies_parsed_at":"2023-12-06T13:28:20.167Z","dependency_job_id":"3c78b47f-7ab9-4fc8-9919-e3199b6bff5d","html_url":"https://github.com/httptoolkit/httpolyglot","commit_stats":{"total_commits":46,"total_committers":3,"mean_commits":"15.333333333333334","dds":"0.28260869565217395","last_synced_commit":"8171638b7b7865ccacbb3bb59e8ea87f8b70b79c"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fhttpolyglot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fhttpolyglot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fhttpolyglot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/httptoolkit%2Fhttpolyglot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/httptoolkit","download_url":"https://codeload.github.com/httptoolkit/httpolyglot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T01:13:45.005Z","updated_at":"2025-04-07T15:07:57.971Z","avatar_url":"https://github.com/httptoolkit.png","language":"TypeScript","readme":"# Httpolyglot [![Build Status](https://github.com/httptoolkit/httpolyglot/workflows/CI/badge.svg)](https://github.com/httptoolkit/httpolyglot/actions) [![Available on NPM](https://img.shields.io/npm/v/@httptoolkit/httpolyglot.svg)](https://npmjs.com/package/@httptoolkit/httpolyglot)\n\n\u003e _Part of [HTTP Toolkit](https://httptoolkit.com): powerful tools for building, testing \u0026 debugging HTTP(S)_\n\nA module for serving HTTP, HTTPS and HTTP/2 connections, all over the same port.\n\nForked from the original [`httpolyglot`](https://github.com/mscdex/httpolyglot) to fix various issues required for [HTTP Toolkit](https://httptoolkit.com), including:\n\n* Support for HTTP/2\n* Fixing `tlsClientError`: https://github.com/mscdex/httpolyglot/pull/11\n* Include initially sniffed bytes aren't lost in subsequent `clientError` events (https://github.com/mscdex/httpolyglot/issues/13)\n* Dropping support for very old versions of Node (and thereby simplifying the code somewhat)\n* Converting to TypeScript\n* Event subscription support (subscribe to `server.on(x, ...)` to hear about `x` from _all_ internal servers - HTTP/2, HTTP/1, TLS and net)\n\nRequirements\n============\n\n* [node.js](http://nodejs.org/) -- v12.0.0 or newer\n\n\nInstall\n============\n\n    npm install @httptoolkit/httpolyglot\n\n\nExamples\n========\n\n* Simple usage:\n\n```javascript\nconst httpolyglot = require('@httptoolkit/httpolyglot');\nconst fs = require('fs');\n\nhttpolyglot.createServer({\n  key: fs.readFileSync('server.key'),\n  cert: fs.readFileSync('server.crt')\n}, function(req, res) {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end((req.socket.encrypted ? 'HTTPS' : 'HTTP') + ' Connection!');\n}).listen(9000, 'localhost', function() {\n  console.log('httpolyglot server listening on port 9000');\n  // visit http://localhost:9000 and https://localhost:9000 in your browser ...\n});\n```\n\n* Simple redirect of all http connections to https:\n\n```javascript\nconst httpolyglot = require('@httptoolkit/httpolyglot');\nconst fs = require('fs');\n\nhttpolyglot.createServer({\n  key: fs.readFileSync('server.key'),\n  cert: fs.readFileSync('server.crt')\n}, function(req, res) {\n  if (!req.socket.encrypted) {\n    res.writeHead(301, { 'Location': 'https://localhost:9000' });\n    return res.end();\n  }\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('Welcome, HTTPS user!');\n}).listen(9000, 'localhost', function() {\n  console.log('httpolyglot server listening on port 9000');\n  // visit http://localhost:9000 and https://localhost:9000 in your browser ...\n});\n```\n\n\nAPI\n===\n\nExports\n-------\n\n* **Server** - A class similar to https.Server (except instances have `setTimeout()` from http.Server).\n\n* **createServer**(\u003c _object_ \u003etlsConfig[, \u003c _function_ \u003erequestListener]) - _Server_ - Creates and returns a new Server instance.\n\nHow it Works\n============\n\nTLS and HTTP connections are easy to distinguish based on the first byte sent by clients trying to connect. See [this comment](https://github.com/mscdex/httpolyglot/issues/3#issuecomment-173680155) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttptoolkit%2Fhttpolyglot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttptoolkit%2Fhttpolyglot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttptoolkit%2Fhttpolyglot/lists"}