Compare commits
10 Commits
improvemen
...
developmen
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | 32b843aaf3 | |
William | 66e97ab935 | |
williamlardier | 8425d23e04 | |
williamlardier | 2e3d13c5b9 | |
William | ec4e28f050 | |
williamlardier | 435c7436d0 | |
williamlardier | aae50a9096 | |
williamlardier | 1881146b28 | |
williamlardier | 6c600cd02f | |
williamlardier | 72108aed4f |
|
@ -0,0 +1 @@
|
|||
index.d.ts
|
|
@ -0,0 +1,15 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
commonjs: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: 'airbnb-base',
|
||||
overrides: [
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
},
|
||||
rules: {
|
||||
},
|
||||
};
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"ignorePatterns": ["build/**/*.js", "build/**/*.d.ts"],
|
||||
"overrides": [
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
}
|
||||
}
|
|
@ -32,5 +32,4 @@ jobs:
|
|||
run: yarn install --frozen-lockfile
|
||||
- name: run lint
|
||||
run: yarn run eslint
|
||||
- name: run build
|
||||
run: yarn build
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import HttpAgent, { HttpsAgent } from 'agentkeepalive';
|
||||
|
||||
import { HttpsOptions, HttpOptions } from 'agentkeepalive';
|
||||
|
||||
declare namespace http {
|
||||
export interface clientConfigurationDefault {
|
||||
/**
|
||||
* Maximum Socket Number: true if TCP session reuse must be enabled
|
||||
*/
|
||||
maxSockets?: boolean;
|
||||
}
|
||||
|
||||
export class Agent extends HttpAgent {
|
||||
constructor(opts?: HttpOptions, config?: clientConfigurationDefault);
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace https {
|
||||
export interface clientConfigurationDefault {
|
||||
/**
|
||||
* Maximum Socket Number: true if TCP session reuse must be enabled
|
||||
*/
|
||||
maxSockets?: boolean;
|
||||
}
|
||||
|
||||
export class Agent extends HttpsAgent {
|
||||
constructor(opts?: HttpsOptions, config?: clientConfigurationDefault);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
/* eslint-disable global-require */
|
||||
|
||||
exports.http = {
|
||||
Agent: require('./lib/http-agent').default,
|
||||
};
|
||||
|
||||
exports.https = {
|
||||
Agent: require('./lib/https-agent').default,
|
||||
};
|
||||
|
||||
exports.AgentConfiguration = require('./lib/config/agentConfiguration').default;
|
13
index.ts
13
index.ts
|
@ -1,13 +0,0 @@
|
|||
import agentConfiguration from "./lib/config/agentConfiguration";
|
||||
import httpAgent from "./lib/http-agent";
|
||||
import httpsAgent from "./lib/https-agent";
|
||||
|
||||
export const http = {
|
||||
Agent: httpAgent,
|
||||
};
|
||||
|
||||
export const https = {
|
||||
Agent: httpsAgent,
|
||||
};
|
||||
|
||||
export const AgentConfiguration = agentConfiguration;
|
|
@ -1,5 +1,3 @@
|
|||
import * as http from 'http';
|
||||
|
||||
/**
|
||||
* The maximum socket configuration defaults to 50.
|
||||
*/
|
||||
|
@ -10,10 +8,10 @@ const maxSocketsNumber = Number(process.env.MAX_SOCKETS) || 50;
|
|||
* The goal is to enforce a `maxSockets` property to properly
|
||||
* handle load.
|
||||
*/
|
||||
const agentConfiguration: http.AgentOptions = {
|
||||
const agentConfiguration = {
|
||||
keepAlive: true,
|
||||
maxSockets: maxSocketsNumber,
|
||||
maxFreeSockets: maxSocketsNumber,
|
||||
}
|
||||
};
|
||||
|
||||
export default agentConfiguration;
|
||||
exports.default = agentConfiguration;
|
|
@ -1,6 +0,0 @@
|
|||
export default interface clientConfigurationDefault {
|
||||
/**
|
||||
* Maximum Socket Number: true if TCP session reuse must be enabled
|
||||
*/
|
||||
maxSockets?: boolean;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
const HttpAgent = require('agentkeepalive');
|
||||
const agentConfiguration = require('./config/agentConfiguration');
|
||||
|
||||
/**
|
||||
* @class AgentHttp
|
||||
* Abstracts the native HttpAgent class from agentkeepalive to enforce common
|
||||
* networking configuration across components.
|
||||
*/
|
||||
class AgentHttp extends HttpAgent {
|
||||
/**
|
||||
* Constructor for the AgentHttp class
|
||||
*
|
||||
* @param opts - Custom HTTP Agent options
|
||||
* @param config - user-defined default configuration to apply
|
||||
*/
|
||||
constructor(opts, config = {
|
||||
maxSockets: true,
|
||||
}) {
|
||||
// Enforce TCP session reuse configuration, unless explicitely specified.
|
||||
let defaultConfigurations = {};
|
||||
if (config.maxSockets) {
|
||||
defaultConfigurations = agentConfiguration;
|
||||
}
|
||||
super({ ...opts, ...defaultConfigurations });
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = AgentHttp;
|
|
@ -1,33 +0,0 @@
|
|||
import HttpAgent, { HttpOptions } from 'agentkeepalive';
|
||||
import clientConfigurationDefault from './config/default';
|
||||
import agentConfiguration from './config/agentConfiguration';
|
||||
|
||||
/**
|
||||
* @class AgentHttp
|
||||
* Abstracts the native HttpAgent class from agentkeepalive to enforce common
|
||||
* networking configuration across components.
|
||||
*/
|
||||
export default class AgentHttp extends HttpAgent {
|
||||
/**
|
||||
* Constructor for the AgentHttp class
|
||||
*
|
||||
* @param opts - Custom HTTP Agent options
|
||||
* @param config - user-defined default configuration to apply
|
||||
*/
|
||||
constructor(
|
||||
opts?: HttpOptions,
|
||||
config: clientConfigurationDefault = {
|
||||
maxSockets: true,
|
||||
},
|
||||
) {
|
||||
// Enforce TCP session reuse configuration, unless explicitely specified.
|
||||
let defaultConfigurations: HttpOptions = {};
|
||||
if (config.maxSockets) {
|
||||
defaultConfigurations = agentConfiguration;
|
||||
}
|
||||
super({
|
||||
...opts,
|
||||
...defaultConfigurations,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
const { HttpsAgent } = require('agentkeepalive');
|
||||
const agentConfiguration = require('./config/agentConfiguration');
|
||||
|
||||
/**
|
||||
* @class AgentHttps
|
||||
* Abstracts the native HttpsAgent class from agentkeepalive to enforce common
|
||||
* networking configuration across components.
|
||||
*/
|
||||
class AgentHttps extends HttpsAgent {
|
||||
/**
|
||||
* Constructor for the AgentHttps class
|
||||
*
|
||||
* @param opts - Custom HTTPs Agent options
|
||||
* @param config - user-defined default configuration to apply
|
||||
*/
|
||||
constructor(opts, config = {
|
||||
maxSockets: true,
|
||||
}) {
|
||||
// Enforce TCP session reuse configuration, unless explicitely specified.
|
||||
let defaultConfigurations = {};
|
||||
if (config.maxSockets) {
|
||||
defaultConfigurations = agentConfiguration;
|
||||
}
|
||||
super({ ...opts, ...defaultConfigurations });
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = AgentHttps;
|
|
@ -1,33 +0,0 @@
|
|||
import { HttpsAgent, HttpsOptions } from 'agentkeepalive';
|
||||
import clientConfigurationDefault from './config/default';
|
||||
import agentConfiguration from './config/agentConfiguration';
|
||||
|
||||
/**
|
||||
* @class AgentHttps
|
||||
* Abstracts the native HttpsAgent class from agentkeepalive to enforce common
|
||||
* networking configuration across components.
|
||||
*/
|
||||
export default class AgentHttps extends HttpsAgent {
|
||||
/**
|
||||
* Constructor for the AgentHttps class
|
||||
*
|
||||
* @param opts - Custom HTTPs Agent options
|
||||
* @param config - user-defined default configuration to apply
|
||||
*/
|
||||
constructor(
|
||||
opts?: HttpsOptions,
|
||||
config: clientConfigurationDefault = {
|
||||
maxSockets: true,
|
||||
},
|
||||
) {
|
||||
// Enforce TCP session reuse configuration, unless explicitely specified.
|
||||
let defaultConfigurations: HttpsOptions = {};
|
||||
if (config.maxSockets) {
|
||||
defaultConfigurations = agentConfiguration;
|
||||
}
|
||||
super({
|
||||
...opts,
|
||||
...defaultConfigurations,
|
||||
});
|
||||
}
|
||||
}
|
21
package.json
21
package.json
|
@ -1,37 +1,30 @@
|
|||
{
|
||||
"name": "httpagent",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.6",
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"description": "A utility library for networking",
|
||||
"main": "build/index.js",
|
||||
"main": "index.js",
|
||||
"repository": "git@github.com:scality/httpagent.git",
|
||||
"author": "Scality Inc.",
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "tsc --declaration; tsc --build tsconfig.json",
|
||||
"format": "prettier --write \"**/*.{ts,tsx,css,html}\" ",
|
||||
"prepare": "yarn build || true",
|
||||
"eslint": "eslint ./ --ext .js,.ts,.tsx",
|
||||
"eslint-fix": "eslint ./ --ext .js,.ts,.tsx --fix",
|
||||
"eslint-init": "eslint --init",
|
||||
"lint": "eslint ./ --ext .js,.ts,.tsx --format visualstudio --no-color --max-warnings 10 --report-unused-disable-directives"
|
||||
"eslint-init": "eslint --init"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^18.11.9",
|
||||
"agentkeepalive": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
||||
"@typescript-eslint/parser": "^5.44.0",
|
||||
"eslint": "^8.28.0",
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-config-scality": "git+https://github.com/scality/Guidelines#8.2.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-config-scality": "git+https://git.yourcmc.ru/vitalif/zenko-eslint-config-scality.git",
|
||||
"eslint-plugin-import": "^2.25.2",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"prettier": "^2.8.0",
|
||||
"typescript": "^4.9.3"
|
||||
"prettier": "^2.8.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"rootDir": "./",
|
||||
"resolveJsonModule": true,
|
||||
"allowJs": true,
|
||||
"checkJs": false,
|
||||
"outDir": "build",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noEmitOnError": false,
|
||||
"sourceMap": true,
|
||||
"declarationMap": true
|
||||
},
|
||||
"include": ["index.ts", "lib/**/*"],
|
||||
"exclude": ["node_modules/*"],
|
||||
"compileOnSave": true
|
||||
}
|
Loading…
Reference in New Issue