https://github.com/allegiant-js/httpduplex
Unifies http request and response streams.
https://github.com/allegiant-js/httpduplex
duplex http response-stream
Last synced: 14 days ago
JSON representation
Unifies http request and response streams.
- Host: GitHub
- URL: https://github.com/allegiant-js/httpduplex
- Owner: allegiant-js
- License: mit
- Created: 2017-12-27T01:56:58.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-13T15:09:04.000Z (about 8 years ago)
- Last Synced: 2025-11-22T23:25:51.432Z (3 months ago)
- Topics: duplex, http, response-stream
- Language: JavaScript
- Homepage: https://allegiant-js.github.io/httpduplex/
- Size: 303 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
[](https://www.npmjs.com/package/@allegiant/httpduplex)
[](https://travis-ci.org/allegiant-js/httpduplex.svg?branch=master)
[](https://coveralls.io/github/allegiant-js/httpduplex?branch=master)
## Install
```
npm install @allegiant/httpduplex
```
## Usage
The following example can be found at example/index.js
```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](https://github.com/substack/http-duplex).
## Copyright & License
Copyright © 2017 Allegiant. Distributed under the terms of the MIT License, see [LICENSE](https://github.com/allegiant-js/httpduplex/blob/master/LICENSE)
Availble via [npm](https://www.npmjs.com/package/@allegiant/httpduplex) or [github](https://github.com/allegiant-js/httpduplex).