@algolia/requester-node-http 5.1.0 → 5.2.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHttpRequester.d.ts","sourceRoot":"","sources":["../../src/createHttpRequester.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EAAc,SAAS,EAAY,MAAM,wBAAwB,CAAC;AAE9E,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC;IAC/C,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAChC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;IACtB,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC;IACxB;;OAEG;IACH,gBAAgB,EAAE,KAAK,CAAC,cAAc,CAAC;CACxC,CAAC,CAAC;AAOH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,cAAc,EAC1B,gBAAqB,GACtB,GAAE,0BAA+B,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"createHttpRequester.d.ts","sourceRoot":"","sources":["../../src/createHttpRequester.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EAAc,SAAS,EAAY,MAAM,wBAAwB,CAAC;AAE9E,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC;IAC/C,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAChC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;IACtB,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC;IACxB;;OAEG;IACH,gBAAgB,EAAE,KAAK,CAAC,cAAc,CAAC;CACxC,CAAC,CAAC;AAOH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,cAAc,EAC1B,gBAAqB,GACtB,GAAE,0BAA+B,GAAG,SAAS,CAgF7C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/requester-node-http",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Promise-based request library for node using the native http module.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"test": "jest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@algolia/client-common": "5.1
|
|
26
|
+
"@algolia/client-common": "5.2.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@babel/preset-env": "7.25.
|
|
29
|
+
"@babel/preset-env": "7.25.4",
|
|
30
30
|
"@babel/preset-typescript": "7.24.7",
|
|
31
31
|
"@types/jest": "29.5.12",
|
|
32
|
-
"@types/node": "
|
|
32
|
+
"@types/node": "22.5.0",
|
|
33
33
|
"jest": "29.7.0",
|
|
34
|
-
"nock": "13.5.
|
|
35
|
-
"ts-jest": "29.2.
|
|
34
|
+
"nock": "13.5.5",
|
|
35
|
+
"ts-jest": "29.2.5",
|
|
36
36
|
"typescript": "5.5.4"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
@@ -79,7 +79,7 @@ describe('api', () => {
|
|
|
79
79
|
'my-extra-header': 'algolia',
|
|
80
80
|
}),
|
|
81
81
|
}),
|
|
82
|
-
expect.any(Function)
|
|
82
|
+
expect.any(Function),
|
|
83
83
|
);
|
|
84
84
|
});
|
|
85
85
|
});
|
|
@@ -88,10 +88,7 @@ describe('status code handling', () => {
|
|
|
88
88
|
it('sends requests', async () => {
|
|
89
89
|
const body = getStringifiedBody();
|
|
90
90
|
|
|
91
|
-
nock(testQueryBaseUrl, { reqheaders: headers })
|
|
92
|
-
.post('/foo')
|
|
93
|
-
.query(testQueryHeader)
|
|
94
|
-
.reply(200, body);
|
|
91
|
+
nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(200, body);
|
|
95
92
|
|
|
96
93
|
const response = await requester.send(requestStub);
|
|
97
94
|
|
|
@@ -101,10 +98,7 @@ describe('status code handling', () => {
|
|
|
101
98
|
it('resolves status 200', async () => {
|
|
102
99
|
const body = getStringifiedBody();
|
|
103
100
|
|
|
104
|
-
nock(testQueryBaseUrl, { reqheaders: headers })
|
|
105
|
-
.post('/foo')
|
|
106
|
-
.query(testQueryHeader)
|
|
107
|
-
.reply(200, body);
|
|
101
|
+
nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(200, body);
|
|
108
102
|
|
|
109
103
|
const response = await requester.send(requestStub);
|
|
110
104
|
|
|
@@ -116,10 +110,7 @@ describe('status code handling', () => {
|
|
|
116
110
|
it('resolves status 300', async () => {
|
|
117
111
|
const reason = 'Multiple Choices';
|
|
118
112
|
|
|
119
|
-
nock(testQueryBaseUrl, { reqheaders: headers })
|
|
120
|
-
.post('/foo')
|
|
121
|
-
.query(testQueryHeader)
|
|
122
|
-
.reply(300, reason);
|
|
113
|
+
nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(300, reason);
|
|
123
114
|
|
|
124
115
|
const response = await requester.send(requestStub);
|
|
125
116
|
|
|
@@ -133,10 +124,7 @@ describe('status code handling', () => {
|
|
|
133
124
|
message: 'Invalid Application-Id or API-Key',
|
|
134
125
|
});
|
|
135
126
|
|
|
136
|
-
nock(testQueryBaseUrl, { reqheaders: headers })
|
|
137
|
-
.post('/foo')
|
|
138
|
-
.query(testQueryHeader)
|
|
139
|
-
.reply(400, body);
|
|
127
|
+
nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(400, body);
|
|
140
128
|
|
|
141
129
|
const response = await requester.send(requestStub);
|
|
142
130
|
|
|
@@ -157,10 +145,7 @@ describe('status code handling', () => {
|
|
|
157
145
|
|
|
158
146
|
const testStream = Readable.from(generate());
|
|
159
147
|
|
|
160
|
-
nock(testQueryBaseUrl, { reqheaders: headers })
|
|
161
|
-
.post('/foo')
|
|
162
|
-
.query(testQueryHeader)
|
|
163
|
-
.reply(200, testStream);
|
|
148
|
+
nock(testQueryBaseUrl, { reqheaders: headers }).post('/foo').query(testQueryHeader).reply(200, testStream);
|
|
164
149
|
|
|
165
150
|
const response = await requester.send(requestStub);
|
|
166
151
|
|
|
@@ -34,8 +34,7 @@ export function createHttpRequester({
|
|
|
34
34
|
// eslint-disable-next-line prefer-const -- linter thinks this is not reassigned
|
|
35
35
|
let connectTimeout: NodeJS.Timeout | undefined;
|
|
36
36
|
const url = new URL(request.url);
|
|
37
|
-
const path =
|
|
38
|
-
url.search === null ? url.pathname : `${url.pathname}${url.search}`;
|
|
37
|
+
const path = url.search === null ? url.pathname : `${url.pathname}${url.search}`;
|
|
39
38
|
const options: https.RequestOptions = {
|
|
40
39
|
agent: url.protocol === 'https:' ? httpsAgent : httpAgent,
|
|
41
40
|
hostname: url.hostname,
|
|
@@ -52,32 +51,26 @@ export function createHttpRequester({
|
|
|
52
51
|
options.port = url.port;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
const req = (url.protocol === 'https:' ? https : http).request(
|
|
56
|
-
|
|
57
|
-
(response) => {
|
|
58
|
-
let contentBuffers: Buffer[] = [];
|
|
54
|
+
const req = (url.protocol === 'https:' ? https : http).request(options, (response) => {
|
|
55
|
+
let contentBuffers: Buffer[] = [];
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
response.on('data', (chunk) => {
|
|
58
|
+
contentBuffers = contentBuffers.concat(chunk);
|
|
59
|
+
});
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
response.on('end', () => {
|
|
62
|
+
clearTimeout(connectTimeout as NodeJS.Timeout);
|
|
63
|
+
clearTimeout(responseTimeout as NodeJS.Timeout);
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
65
|
+
resolve({
|
|
66
|
+
status: response.statusCode || 0,
|
|
67
|
+
content: Buffer.concat(contentBuffers).toString(),
|
|
68
|
+
isTimedOut: false,
|
|
73
69
|
});
|
|
74
|
-
}
|
|
75
|
-
);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
76
72
|
|
|
77
|
-
const createTimeout = (
|
|
78
|
-
timeout: number,
|
|
79
|
-
content: string
|
|
80
|
-
): NodeJS.Timeout => {
|
|
73
|
+
const createTimeout = (timeout: number, content: string): NodeJS.Timeout => {
|
|
81
74
|
return setTimeout(() => {
|
|
82
75
|
req.destroy();
|
|
83
76
|
|
|
@@ -89,10 +82,7 @@ export function createHttpRequester({
|
|
|
89
82
|
}, timeout);
|
|
90
83
|
};
|
|
91
84
|
|
|
92
|
-
connectTimeout = createTimeout(
|
|
93
|
-
request.connectTimeout,
|
|
94
|
-
'Connection timeout'
|
|
95
|
-
);
|
|
85
|
+
connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
|
|
96
86
|
|
|
97
87
|
req.on('error', (error) => {
|
|
98
88
|
clearTimeout(connectTimeout as NodeJS.Timeout);
|
|
@@ -102,10 +92,7 @@ export function createHttpRequester({
|
|
|
102
92
|
|
|
103
93
|
req.once('response', () => {
|
|
104
94
|
clearTimeout(connectTimeout as NodeJS.Timeout);
|
|
105
|
-
responseTimeout = createTimeout(
|
|
106
|
-
request.responseTimeout,
|
|
107
|
-
'Socket timeout'
|
|
108
|
-
);
|
|
95
|
+
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
|
|
109
96
|
});
|
|
110
97
|
|
|
111
98
|
if (request.data !== undefined) {
|