@algolia/requester-node-http 4.3.0 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,11 +6,11 @@ var http = require('http');
|
|
|
6
6
|
var https = require('https');
|
|
7
7
|
var URL = require('url');
|
|
8
8
|
|
|
9
|
-
/* eslint
|
|
10
|
-
function createNodeHttpRequester() {
|
|
9
|
+
/* eslint functional/prefer-readonly-type: 0 */
|
|
10
|
+
function createNodeHttpRequester({ agent: userGlobalAgent, httpAgent: userHttpAgent, httpsAgent: userHttpsAgent, } = {}) {
|
|
11
11
|
const agentOptions = { keepAlive: true };
|
|
12
|
-
const httpAgent = new http.Agent(agentOptions);
|
|
13
|
-
const httpsAgent = new https.Agent(agentOptions);
|
|
12
|
+
const httpAgent = userHttpAgent || userGlobalAgent || new http.Agent(agentOptions);
|
|
13
|
+
const httpsAgent = userHttpsAgent || userGlobalAgent || new https.Agent(agentOptions);
|
|
14
14
|
return {
|
|
15
15
|
send(request) {
|
|
16
16
|
return new Promise(resolve => {
|
|
@@ -25,7 +25,7 @@ function createNodeHttpRequester() {
|
|
|
25
25
|
...(url.port !== undefined ? { port: url.port || '' } : {}),
|
|
26
26
|
};
|
|
27
27
|
const req = (url.protocol === 'https:' ? https : http).request(options, response => {
|
|
28
|
-
// eslint-disable-next-line functional/no-let
|
|
28
|
+
// eslint-disable-next-line functional/no-let
|
|
29
29
|
let contentBuffers = [];
|
|
30
30
|
response.on('data', chunk => {
|
|
31
31
|
contentBuffers = contentBuffers.concat(chunk);
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Destroyable } from '@algolia/requester-common';
|
|
3
|
+
import * as http from 'http';
|
|
4
|
+
import * as https from 'https';
|
|
2
5
|
import { Requester } from '@algolia/requester-common';
|
|
3
6
|
|
|
4
|
-
export declare function createNodeHttpRequester(): Requester & Destroyable;
|
|
7
|
+
export declare function createNodeHttpRequester({ agent: userGlobalAgent, httpAgent: userHttpAgent, httpsAgent: userHttpsAgent, }?: NodeHttpRequesterOptions): Requester & Destroyable;
|
|
8
|
+
|
|
9
|
+
export declare type NodeHttpRequesterOptions = {
|
|
10
|
+
agent?: https.Agent | http.Agent;
|
|
11
|
+
httpAgent?: http.Agent;
|
|
12
|
+
httpsAgent?: https.Agent;
|
|
13
|
+
};
|
|
5
14
|
|
|
6
15
|
export { }
|
|
@@ -4,11 +4,11 @@ import * as https from 'https';
|
|
|
4
4
|
import { Agent as Agent$1 } from 'https';
|
|
5
5
|
import { parse } from 'url';
|
|
6
6
|
|
|
7
|
-
/* eslint
|
|
8
|
-
function createNodeHttpRequester() {
|
|
7
|
+
/* eslint functional/prefer-readonly-type: 0 */
|
|
8
|
+
function createNodeHttpRequester({ agent: userGlobalAgent, httpAgent: userHttpAgent, httpsAgent: userHttpsAgent, } = {}) {
|
|
9
9
|
const agentOptions = { keepAlive: true };
|
|
10
|
-
const httpAgent = new Agent(agentOptions);
|
|
11
|
-
const httpsAgent = new Agent$1(agentOptions);
|
|
10
|
+
const httpAgent = userHttpAgent || userGlobalAgent || new Agent(agentOptions);
|
|
11
|
+
const httpsAgent = userHttpsAgent || userGlobalAgent || new Agent$1(agentOptions);
|
|
12
12
|
return {
|
|
13
13
|
send(request) {
|
|
14
14
|
return new Promise(resolve => {
|
|
@@ -23,7 +23,7 @@ function createNodeHttpRequester() {
|
|
|
23
23
|
...(url.port !== undefined ? { port: url.port || '' } : {}),
|
|
24
24
|
};
|
|
25
25
|
const req = (url.protocol === 'https:' ? https : http).request(options, response => {
|
|
26
|
-
// eslint-disable-next-line functional/no-let
|
|
26
|
+
// eslint-disable-next-line functional/no-let
|
|
27
27
|
let contentBuffers = [];
|
|
28
28
|
response.on('data', chunk => {
|
|
29
29
|
contentBuffers = contentBuffers.concat(chunk);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/requester-node-http",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Promise-based request library for node using the native http module.",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@algolia/requester-common": "4.
|
|
20
|
+
"@algolia/requester-common": "4.5.1"
|
|
21
21
|
}
|
|
22
22
|
}
|