Socket
Socket
Sign inDemoInstall

@allegiant/httpduplex

Package Overview
Dependencies
0
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @allegiant/httpduplex

Unifies http request and response streams.


Version published
Weekly downloads
4
increased by100%
Maintainers
2
Install size
889 kB
Created
Weekly downloads
 

Changelog

Source

0.3.6 (12/28/2017)

  • include example, remove npm prefer global, republished

Readme

Source

HttpDuplex

Unifies http request and response streams.

There be 🐲 here! The API and functionality are being cemented, anything before a 1.0.0 release is subject to change.

Install

npm install @allegiant/httpduplex

Usage

The following example can be found at example/index.js

const fs = require('fs');
const http = require('http');
const httpDuplex = require('@allegiant/httpduplex');

var server = http.createServer(function (req, res) {
    var dup = new httpDuplex(req, res);
    console.log(dup.method + ' ' + dup.url); // eslint-disable-line

    if (dup.url == '/') {
        dup.setHeader('content-type', 'text/plain');
        if (dup.method === 'POST') {
            let size = 0;
            dup.on('data', buf => size += buf.length)
               .on('end', () => dup.end(size + '\n'));
        } else {
            fs.createReadStream('README.md').pipe(dup);
        }
    } else {
        dup.setHeader('content-type', 'text/html');
        dup.statusCode = 404;
        dup.end('Not found');
    }
})
.on('listening', function () {
    console.log('Listening http://localhost:' + server.address().port + '/'); // eslint-disable-line
})
.listen(7000);

Example

Running the following command will start up a simple http server:

node example/index.js

Thanks

This began as a compatiblity rewrite of http-duplex.

Copyright © 2017 Allegiant. Distributed under the terms of the MIT License, see LICENSE

Availble via npm or github.

FAQs

Last updated on 27 Dec 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc