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 2.2.5 to 2.3.0

37

lib/router/sequential.js

@@ -15,3 +15,5 @@ const Trouter = require('trouter')

})
config.cacheSize = config.cacheSize || 1000
if (config.cacheSize === undefined) {
config.cacheSize = 1000
}
config.id = config.id || (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase()

@@ -43,11 +45,25 @@

router.lookup = (req, res, step) => {
req.url = req.url || '/'
req.originalUrl = req.originalUrl || req.url
req.path = req.url.split('?')[0]
if (!req.url) {
req.url = '/'
}
if (!req.originalUrl) {
req.originalUrl = req.url
}
const varsIndex = req.url.indexOf('?')
if (varsIndex > 0) {
req.path = req.url.slice(0, varsIndex)
} else {
req.path = req.url
}
const reqCacheKey = `${req.method + req.path}`
let match = cache.get(reqCacheKey)
if (!match) {
let match
if (config.cacheSize > 0) {
const reqCacheKey = `${req.method + req.path}`
match = cache.get(reqCacheKey)
if (!match) {
match = router.find(req.method, req.path)
cache.set(reqCacheKey, match)
}
} else {
match = router.find(req.method, req.path)
cache.set(reqCacheKey, match)
}

@@ -71,3 +87,6 @@

// middlewares invocation
req.params = Object.assign(req.params || {}, match.params)
if (!req.params) {
req.params = {}
}
req.params = Object.assign(req.params, match.params)

@@ -74,0 +93,0 @@ return next(middlewares, req, res, 0, routers, config.defaultRoute, config.errorHandler)

@@ -28,6 +28,9 @@ const uWS = require('uWebSockets.js')

if (isLast) {
buffer || (buffer = chunk)
if (!buffer) {
buffer = chunk
}
reqWrapper.body = buffer
res.finished || handler(reqWrapper, resWrapper)
if (!res.finished) {
handler(reqWrapper, resWrapper)
}
} else {

@@ -41,4 +44,4 @@ if (buffer) {

})
} else {
res.finished || handler(reqWrapper, resWrapper)
} else if (!res.finished) {
handler(reqWrapper, resWrapper)
}

@@ -75,4 +78,6 @@ })

constructor (uRequest) {
const q = uRequest.getQuery()
const uRequestKeys = Object.keys(uRequest)
this.req = uRequest
this.url = uRequest.getUrl() + (uRequest.getQuery() ? '?' + uRequest.getQuery() : '')
this.url = uRequest.getUrl() + (q ? '?' + q : '')
this.method = uRequest.getMethod().toUpperCase()

@@ -82,5 +87,5 @@ this.body = null

uRequest.forEach((k, v) => {
this.headers[k] = v
})
for (let i = 0, len = uRequestKeys.length; i < len; i++) {
this.headers[uRequestKeys[i]] = uRequest[uRequestKeys[i]]
}
}

@@ -130,8 +135,11 @@

end (data = '') {
const headerKeys = Object.keys(this.headers)
this.res.writeStatus(`${this.statusCode} ${this.statusMessage}`)
this.res.writeHeader('Date', this.server._date)
Object.keys(this.headers).forEach(name => {
this.res.writeHeader(name, this.headers[name])
})
for (let i = 0, len = headerKeys.length; i < len; i++) {
this.res.writeHeader(headerKeys[i], this.headers[headerKeys[i]])
}
this.headersSent = true

@@ -138,0 +146,0 @@ this.finished = true

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

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -38,3 +38,3 @@ # 0http

As this is an iterative regular expression matching router, it tends to be slower than `find-my-way` when the number of registered routes increases; to mitigate this issue, we use
an internal LRU cache to store the matching results of the previous requests, resulting on a super-fast matching process.
an internal(optional) LRU cache to store the matching results of the previous requests, resulting on a super-fast matching process.

@@ -74,3 +74,3 @@ Supported HTTP verbs: `GET, HEAD, PATCH, OPTIONS, CONNECT, DELETE, TRACE, POST, PUT`

```
- **cacheSize**: Router matching LRU cache size. Default value: `1000`
- **cacheSize**: Router matching LRU cache size. A given value <= 0 will disable the cache. Default value: `1000`
- **errorHandler**: Global error handler function. Default value:

@@ -77,0 +77,0 @@ ```js

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