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

0http

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

0http - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

68

lib/server/low.js

@@ -5,12 +5,10 @@ const uWS = require('uWebSockets.js')

module.exports = (config = {}) => {
const handlers = {
request: (req, res) => {
res.statusCode = 404
res.statusMessage = 'Not Found'
let handler = (req, res) => {
res.statusCode = 404
res.statusMessage = 'Not Found'
res.end()
}
res.end()
}
const server = uWS.App(config).any('/*', (res, req) => {
const uServer = uWS.App(config).any('/*', (res, req) => {
res.finished = false

@@ -22,3 +20,3 @@ res.onAborted(() => {

const reqWrapper = new HttpRequest(req)
const resWrapper = new HttpResponse(res, server)
const resWrapper = new HttpResponse(res, uServer)

@@ -35,3 +33,3 @@ const method = reqWrapper.method

reqWrapper.body = buffer
res.finished || handlers[REQUEST_EVENT](reqWrapper, resWrapper)
res.finished || handler(reqWrapper, resWrapper)
} else {

@@ -46,14 +44,25 @@ if (buffer) {

} else {
res.finished || handlers[REQUEST_EVENT](reqWrapper, resWrapper)
res.finished || handler(reqWrapper, resWrapper)
}
})
server.on = (event, cb) => {
handlers[event] = cb
uServer._date = new Date().toUTCString()
const timer = setInterval(() => (uServer._date = new Date().toUTCString()), 1000)
const facade = {
on (event, cb) {
if (event !== REQUEST_EVENT) throw new Error(`Given "${event}" event is not supported!`)
handler = cb
},
close () {
clearInterval(timer)
uWS.us_listen_socket_close(uServer._socket)
}
}
facade.listen = facade.start = (port, cb) => {
uServer.listen(port, socket => {
uServer._socket = socket
server.start = (port, cb) => {
server.listen(port, socket => {
server._socket = socket
cb(socket)

@@ -63,20 +72,13 @@ })

server._date = new Date().toUTCString()
const timer = setInterval(() => (server._date = new Date().toUTCString()), 1000)
server.close = () => {
clearInterval(timer)
uWS.us_listen_socket_close(server._socket)
}
return server
return facade
}
class HttpRequest {
constructor (req) {
this.req = req
constructor (uRequest) {
this.req = uRequest
this.url = req.getUrl()
this.url = uRequest.getUrl()
this.originalUrl = this.url
this.method = req.getMethod().toUpperCase()
this.method = uRequest.getMethod().toUpperCase()

@@ -86,7 +88,7 @@ this.body = null

this.headers = {}
req.forEach((k, v) => {
uRequest.forEach((k, v) => {
this.headers[k] = v
})
this.query = req.getQuery()
this.query = uRequest.getQuery()
}

@@ -100,5 +102,5 @@

class HttpResponse {
constructor (res, server) {
this.res = res
this.server = server
constructor (uResponse, uServer) {
this.res = uResponse
this.server = uServer

@@ -105,0 +107,0 @@ this.statusCode = 200

{
"name": "0http",
"version": "1.2.1",
"version": "1.2.2",
"description": "Cero friction HTTP request router. The need for speed!",

@@ -31,3 +31,3 @@ "main": "index.js",

"nyc": "^14.1.1",
"standard": "^13.0.2",
"standard": "^13.1.0",
"supertest": "^4.0.2",

@@ -34,0 +34,0 @@ "uWebSockets.js": "github:uNetworking/uWebSockets.js#v15.11.0"

@@ -123,4 +123,9 @@ # 0http

})
// ...
server.close()
```
## Benchmarks (22/07/2019)

@@ -127,0 +132,0 @@ **Node version**: v10.16.0

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