Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Https = require('https');
const Hoek = require('@hapi/hoek');
const Joi = require('@hapi/joi');
const Wreck = require('@hapi/wreck');
const internals = {
NS_PER_SEC: 1e9
};
internals.defaults = {
httpClient: {
request: Wreck.request.bind(Wreck),
parseCacheControl: Wreck.parseCacheControl.bind(Wreck)
},
xforward: false,
passThrough: false,
redirects: false,
timeout: 1000 * 60 * 3, // Timeout request after 3 minutes
localStatePassThrough: false, // Pass cookies defined by the server upstream
maxSockets: Infinity,
downstreamResponseTime: false
};
internals.schema = Joi.object({
httpClient: Joi.object({
request: Joi.func(),
parseCacheControl: Joi.func()
}),
it('uses a custom http-client', async () => {
const upstream = Hapi.server();
upstream.route({ method: 'GET', path: '/', handler: () => 'ok' });
await upstream.start();
const httpClient = {
request: Wreck.request.bind(Wreck),
parseCacheControl: Wreck.parseCacheControl.bind(Wreck)
};
const server = Hapi.server();
await server.register(H2o2);
server.route({ method: 'GET', path: '/', handler: { proxy: { host: 'localhost', port: upstream.info.port, httpClient } } });
const res = await server.inject('/');
expect(res.payload).to.equal('ok');
});
});