Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-close-channel

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-close-channel

Express middleware for managing and closing HTTP channels

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

License: MIT

http-close-channel

Express middleware for managing and closing HTTP channels. This middleware sends HTTP Connection Close headers to prompt the client to close the socket connection. This is useful for the following cases:

  1. ensuring that HTTP traffic is evenly distributed across application replicas (e.g., even load distribution across pods in Kubernetes)
  2. closing sockets during graceful shutdown

Middleware Options

The middleware takes the following options:

optiontypedescriptiondefaultfrom version
gracefulShutdownBooleanEnable closing sockets after the app receives a SIGTERM signalfalse1.0.0
maxRequestsIntegerSet the number of requests per socket connection before the middleware will close the socket1001.0.0
loggerObjectA logger object (see example below)null no logging1.0.0

Example usage

The middleware can be added to an express app with the following steps...

  1. include the package...
npm install http-close-channel --save
  1. apply the middleware to the app...
// include the middleware
const httpCloseChannel = require('http-close-channel');

// create the app object
const app = express();

// add the middleware to the apps stack...
app.use(httpCloseChannel({
  maxRequests: 50,
  gracefulShutdown: true,
}));

Providing a logger

The middleware will make standard logging calls (e.g., logger.info(...), logger.warn(...)). This option has been tested with a bunyan logger. For example:

const bunyan = require('bunyan');

// create the app object
const app = express();

// create a bunyan based app logger
const loggerConfig = {
  name: 'k8s-test-utils',
  streams: [
    {
      level: 'debug',
      type: 'stream',
      stream: process.stdout,
    },
  ],
};
const appLogger = bunyan.createLogger(loggerConfig);

// pass the logger to the middleware
app.use(httpCloseChannel({
  logger: appLogger,
}));

FAQs

Package last updated on 23 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc