Skip to content

Commit

Permalink
Merge 96c4351 into c22c297
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed May 25, 2020
2 parents c22c297 + 96c4351 commit 6fa29d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/middleware/proxy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const url = require('url')
const http = require('http')
const httpProxy = require('http-proxy')
const _ = require('lodash')

Expand Down Expand Up @@ -42,11 +43,13 @@ function parseProxyConfig (proxies, config) {
port = config.port
}
const changeOrigin = proxyConfiguration.changeOrigin || false
const keepAliveAgent = new http.Agent({ keepAlive: true })
const proxy = httpProxy.createProxyServer({
target: { host: hostname, port, https, protocol },
xfwd: true,
changeOrigin: changeOrigin,
secure: config.proxyValidateSSL
secure: config.proxyValidateSSL,
agent: keepAliveAgent
})

;['proxyReq', 'proxyRes'].forEach(function (name) {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/middleware/proxy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,13 @@ describe('middleware.proxy', () => {
it('should handle empty proxy config', () => {
expect(m.parseProxyConfig({})).to.deep.equal([])
})

it('should use agent with keepAlive=true', () => {
const proxy = { '/base': 'http://localhost:8000/proxy' }
const parsedProxyConfig = m.parseProxyConfig(proxy, {})
expect(parsedProxyConfig).to.have.length(1)
expect(parsedProxyConfig[0].proxy.options.agent).to.containSubset({
keepAlive: true
})
})
})

0 comments on commit 6fa29d3

Please sign in to comment.