Showing 30 of 123 total issues
File http-api.js
has 406 lines of code (exceeds 250 allowed). Consider refactoring. Open
const toxy = require('../..')
const expect = require('chai').expect
const supertest = require('supertest')
suite('http api', function () {
Function throttle
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function throttle (opts) {
opts = opts || {}
const delay = +opts.threshold || +opts.delay || 100
const chunkSize = +opts.bps || +opts.bytes || +opts.chunk || 1024
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function slowRead
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function slowRead (opts) {
opts = opts || {}
var threshold = +opts.threshold || 1000
var chunkSize = +opts.chunk || +opts.bps || 1024
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function abort
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function abort (opts) {
if (typeof opts === 'number') {
opts = { delay: opts }
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File toxy.js
has 263 lines of code (exceeds 250 allowed). Consider refactoring. Open
const http = require('http')
const sinon = require('sinon')
const expect = require('chai').expect
const toxy = require('..')
const supertest = require('supertest')
Function exports
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function (opts) {
opts = opts || {}
const admin = new Admin(opts)
Function slowRead
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function slowRead (opts) {
opts = opts || {}
var threshold = +opts.threshold || 1000
var chunkSize = +opts.chunk || +opts.bps || 1024
Function responseStatus
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function responseStatus (opts) {
opts = parseOptions(opts)
const lower = +opts.lower
const higher = +opts.higher
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function throttle
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function throttle (opts) {
opts = opts || {}
const delay = +opts.threshold || +opts.delay || 100
const chunkSize = +opts.bps || +opts.bytes || +opts.chunk || 1024
Function slowRead
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
return function slowRead (req, res, next) {
var buf = []
var ended = false
var closed = false
var _push = Object.getPrototypeOf(req).push
Function throttle
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
return function throttle (req, res, next) {
var _end = res.end
var _write = res.write
// Cache payload
Function slowClose
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function slowClose (opts) {
opts = opts || {}
const delay = +opts || +opts.delay || 1000
return function slowClose (req, res, next) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function matchHeaders
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function matchHeaders (httpObj, headers) {
return Object.keys(headers).every(function (key) {
const rule = headers[key]
const value = (httpObj.headers || httpObj._headers || {})[key.toLowerCase()]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function body
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function body (opts) {
opts = opts || {}
const match = opts.match
const limit = opts.limit || '5mb'
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function rateLimit
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function rateLimit (opts) {
opts = opts || {}
const code = +opts.code || 429
const limit = +opts.limit || 10
Function slowClose
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function slowClose (opts) {
opts = opts || {}
const delay = +opts || +opts.delay || 1000
return function slowClose (req, res, next) {
Function body
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function body (opts) {
opts = opts || {}
const match = opts.match
const limit = opts.limit || '5mb'
Function createDirective
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function createDirective (req, res, type) {
const body = req.body
const toxy = getStack(req)
const directives = req.toxy[type]
Function create
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.create = function (req, res) {
const toxy = req.toxy
const body = req.body
if (!body || !body.path) {
Function slowClose
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
return function slowClose (req, res, next) {
// Cache native methods
const proto = Object.getPrototypeOf(res)
// Store state