|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | 3 | const { test } = require('tap') |
4 | | -const { Client } = require('..') |
| 4 | +const { Client, Pool } = require('..') |
5 | 5 | const { createServer } = require('http') |
6 | 6 | const proxy = require('proxy') |
7 | 7 |
|
@@ -82,6 +82,41 @@ test('connect through proxy with auth', async (t) => { |
82 | 82 | client.close() |
83 | 83 | }) |
84 | 84 |
|
| 85 | +test('connect through proxy (with pool)', async (t) => { |
| 86 | + t.plan(3) |
| 87 | + |
| 88 | + const server = await buildServer() |
| 89 | + const proxy = await buildProxy() |
| 90 | + |
| 91 | + const serverUrl = `http://localhost:${server.address().port}` |
| 92 | + const proxyUrl = `http://localhost:${proxy.address().port}` |
| 93 | + |
| 94 | + server.on('request', (req, res) => { |
| 95 | + t.strictEqual(req.url, '/hello?foo=bar') |
| 96 | + res.setHeader('content-type', 'application/json') |
| 97 | + res.end(JSON.stringify({ hello: 'world' })) |
| 98 | + }) |
| 99 | + |
| 100 | + const pool = new Pool(proxyUrl) |
| 101 | + |
| 102 | + const response = await pool.request({ |
| 103 | + method: 'GET', |
| 104 | + path: serverUrl + '/hello?foo=bar' |
| 105 | + }) |
| 106 | + |
| 107 | + response.body.setEncoding('utf8') |
| 108 | + let data = '' |
| 109 | + for await (const chunk of response.body) { |
| 110 | + data += chunk |
| 111 | + } |
| 112 | + t.strictEqual(response.statusCode, 200) |
| 113 | + t.deepEqual(JSON.parse(data), { hello: 'world' }) |
| 114 | + |
| 115 | + server.close() |
| 116 | + proxy.close() |
| 117 | + pool.close() |
| 118 | +}) |
| 119 | + |
85 | 120 | function buildServer () { |
86 | 121 | return new Promise((resolve, reject) => { |
87 | 122 | const server = createServer() |
|
0 commit comments