Socket
Book a DemoInstallSign in
Socket

@allegiant/httpduplex

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@allegiant/httpduplex

Unifies http request and response streams.

latest
Source
npmnpm
Version
0.3.6
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
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

Package last updated on 27 Dec 2017

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