🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

@mafintosh/turbo-http

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

@mafintosh/turbo-http

Blazing fast low level http server

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

turbo-http

A low level http library for Node.js based on turbo-net

npm install @mafintosh/turbo-http

WIP, this module is already really fast but there are some HTTP features missing and easy perf gains to be had :D :D :D

On my laptop I can serve simple hello world payloads at around 100k requests/seconds compared to 10k requests/second using node core.

Usage

const turbo = require('@mafintosh/turbo-http')

const server = turbo.createServer(function (req, res) {
  res.setHeader('Content-Length', '11')
  res.write(Buffer.from('hello world'))
})

server.listen(8080)

API

server = turbo.createServer([onrequest])

Create a new http server. Inherits from the turbo-net tcp server

server.on('request', req, res)

Emitted when a new http request is received.

res.statusCode = code

Set the http status

res.setHeader(name, value)

Set a http header

res.write(buf, [length], [callback])

Write a buffer. When the callback is called, the buffer has been completely flushed to the underlying socket and is safe to reuse for other purposes

res.writev(buffers, [lengths], [callback])

Write more that one buffer at once.

res.end([buf], [length], [callback])

End the request. Only needed if you do not provide a Content-Length.

req.url

Request url

req.method

Request method

value = req.getHeader(name)

Get a request header.

headers = req.getAllHeaders()

Get all request headers as a map.

req.ondata(buffer, start, length)

Called when there is data read. If you use the buffer outside of this function you should copy it.

req.onend()

Called when the request is fully read.

Acknowledgements

This project was kindly sponsored by nearForm.

License

MIT

FAQs

Package last updated on 02 Mar 2018

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