-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathkeep-alive-header.test.ts
56 lines (53 loc) · 2.13 KB
/
keep-alive-header.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { strict as assert } from 'node:assert';
import { describe, it, beforeAll, afterAll } from 'vitest';
import urllib from '../src';
import { startServer } from './fixtures/server';
import { sleep } from './utils';
describe('keep-alive-header.test.ts', () => {
const keepAliveTimeout = 2000;
let close: any;
let _url: string;
beforeAll(async () => {
const { closeServer, url } = await startServer({ keepAliveTimeout });
close = closeServer;
_url = url;
});
afterAll(async () => {
await close();
});
it('should handle Keep-Alive header and not throw reset error', async () => {
let count = 0;
// const max = process.env.CI && process.platform !== 'win32' ? 10 : 2;
const max = 2;
while (count < max) {
count++;
let response = await urllib.request(_url);
assert.equal(response.status, 200);
// console.log(response.headers);
assert.equal(response.headers.connection, 'keep-alive');
assert.equal(response.headers['keep-alive'], 'timeout=2');
response = await urllib.request(_url);
assert.equal(response.status, 200);
// console.log(response.headers);
assert.equal(response.headers.connection, 'keep-alive');
assert.equal(response.headers['keep-alive'], 'timeout=2');
response = await urllib.request(_url);
assert.equal(response.status, 200);
// console.log(response.headers);
assert.equal(response.headers.connection, 'keep-alive');
assert.equal(response.headers['keep-alive'], 'timeout=2');
response = await urllib.request(_url);
assert.equal(response.status, 200);
// console.log(response.headers);
assert.equal(response.headers.connection, 'keep-alive');
assert.equal(response.headers['keep-alive'], 'timeout=2');
response = await urllib.request(_url);
assert.equal(response.status, 200);
// console.log(response.headers);
assert.equal(response.headers.connection, 'keep-alive');
assert.equal(response.headers['keep-alive'], 'timeout=2');
assert(parseInt(response.headers['x-requests-persocket'] as string) > 1);
await sleep(keepAliveTimeout);
}
});
});