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

httpiped

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpiped

turn http.Server instances into readable streams

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

HTTPiped

turn http.Server instances into readable streams

HTTPiped allows you to wrap an instance of http.Server into a Readable Stream in objectMode, opening up the opportunity to create stream-based middleware or micro-frameworks with ease.

Installation

npm install httpiped

Example

server.js

var HTTPiped = require("httpiped");
var http = require("http");

// middleware
var logger = require("./logger");
var handler = require("./handler");

var server = http.createServer();
var stream = new HTTPiped(server);

stream.pipe(logger())
      .pipe(handler());

server.listen(8080);

logger.js

var stream = require("stream");

var createLogger = function() {
    var logger = new stream.Transform({objectMode: true});

    logger._transform = function(client, encoding, done) {
        var conn = client.req.connection;
        console.log("Request from " + conn.remoteAddress);
        this.push(client);
        done();
    }

    return logger;
}

module.exports = createLogger;

handler.js

var stream = require("stream");

var createHandler = function() {
    var handler = new stream.Transform({objectMode: true});

    handler._transform = function(client, encoding, done) {
        var path = client.req.url;
        var split = path.split("/");

        client.res.end(JSON.stringify(split) + "\n");

        this.push(client);
        done();
    }

    return handler;
}

module.exports = createHandler;

Keywords

FAQs

Package last updated on 29 Jun 2014

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